#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define TFT_CS 5
#define TFT_DC 2
#define TFT_MOSI 23
#define TFT_CLK 18
#define CLK 34
#define DT 35
#define SW 32
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
int lastStateCLK;
bool lightState = false;
int value = 0;
void setup() {
Serial.begin(115200);
pinMode(CLK, INPUT);
pinMode(DT, INPUT);
pinMode(SW, INPUT);
tft.begin();
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
lastStateCLK = digitalRead(CLK);
tft.setCursor(40, 100);
tft.print("START");
}
void loop() {
int currentStateCLK = digitalRead(CLK);
if (currentStateCLK != lastStateCLK) {
if (digitalRead(DT) != currentStateCLK) {
value++;
} else {
value--;
}
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(40, 80);
tft.print("Value:");
tft.setCursor(60, 120);
tft.print(value);
}
lastStateCLK = currentStateCLK;
if (digitalRead(SW) == LOW) {
lightState = !lightState;
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(20, 100);
if (lightState) {
tft.print("LIGHT ON");
} else {
tft.print("LIGHT OFF");
}
delay(300);
}
}Loading
ili9341-cap-touch
ili9341-cap-touch