#include <Encoder.h>
#include <ILI9341_t3.h>
#include <ILI9341_t3_Controls.h>
#include <font_Arial.h>
#include <Colors.h>
// Encoder setup
Encoder enc1(2, 3); // Encoder 1 connected to pins 2 and 3
Encoder enc2(4, 5); // Encoder 2 connected to pins 4 and 5
Encoder enc3(6, 7); // Encoder 3 connected to pins 6 and 7
// Display setup
#define FONT_TITLE Arial_16
#define FONT_DATA Arial_10
#define TFT_DC 9
#define TFT_CS 10
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
// Graph settings
#define X_ORIGIN 50
#define Y_ORIGIN 200
#define X_WIDE 250
#define Y_HIGH 150
#define X_LOSCALE 0
#define X_HISCALE 1024
#define X_INC 50
#define Y_LOSCALE -1
#define Y_HISCALE 1024
#define Y_INC 100
#define TEXTCOLOR C_WHITE
#define GRIDCOLOR C_GREY
#define AXISCOLOR C_YELLOW
#define BACKCOLOR C_BLACK
#define PLOTCOLOR C_DKGREY
#define VOLTSCOLOR C_RED
#define SINCOLOR C_GREEN
#define COSCOLOR C_BLUE
unsigned long oldTime;
float x;
int Enc1ID, Enc2ID, Enc3ID;
ILI9341_t3 Display(TFT_CS, TFT_DC);
CGraph MyGraph(&Display, X_ORIGIN, Y_ORIGIN, X_WIDE, Y_HIGH, X_LOSCALE, X_HISCALE, X_INC, Y_LOSCALE, Y_HISCALE, Y_INC);
void setup() {
Serial.begin(57600);
Display.begin();
Display.setRotation(1);
Display.fillScreen(C_BLACK);
MyGraph.init("Teensy Graphing", "Sample Number", "Encoder Position", TEXTCOLOR, GRIDCOLOR, AXISCOLOR, BACKCOLOR, PLOTCOLOR, FONT_TITLE, FONT_DATA);
Enc1ID = MyGraph.add("Encoder 1", VOLTSCOLOR);
Enc2ID = MyGraph.add("Encoder 2", SINCOLOR);
Enc3ID = MyGraph.add("Encoder 3", COSCOLOR);
MyGraph.drawGraph();
MyGraph.setMarkerSize(Enc1ID, 0);
MyGraph.setMarkerSize(Enc2ID, 1);
MyGraph.setMarkerSize(Enc3ID, 2);
}
void loop() {
long enc1Pos = enc1.read();
long enc2Pos = enc2.read();
long enc3Pos = enc3.read();
MyGraph.setX(x);
MyGraph.plot(Enc1ID, enc1Pos);
MyGraph.plot(Enc2ID, enc2Pos);
MyGraph.plot(Enc3ID, enc3Pos);
x += 1;
delay(10);
}