Created
August 4, 2020 00:45
-
-
Save buzzkillb/2b6381632f73ee965e1c9329163fdfd3 to your computer and use it in GitHub Desktop.
ESP32 TTGO button 1 and 2 masher with screen and serial example display
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//simple button masher esp32 ttgo | |
#include <TFT_eSPI.h> | |
#include <SPI.h> | |
#define BUTTON1PIN 35 | |
#define BUTTON2PIN 0 | |
TFT_eSPI tft = TFT_eSPI(); | |
void IRAM_ATTR toggleButton1() { | |
Serial.println("Button 1 Pressed!"); | |
tft.fillScreen(TFT_BLACK); | |
tft.setCursor(0, 30); | |
tft.drawLine(0, 35, 250, 35, TFT_BLUE); | |
tft.setFreeFont(&Orbitron_Light_24); | |
tft.setTextColor(TFT_GREEN, TFT_BLACK); | |
tft.print("Button 1"); | |
tft.setCursor(0, 60); | |
tft.print("Pressed!"); | |
} | |
void IRAM_ATTR toggleButton2() { | |
Serial.println("Button 2 Pressed!"); | |
tft.fillScreen(TFT_BLACK); | |
tft.setCursor(0, 30); | |
tft.drawLine(0, 35, 250, 35, TFT_BLUE); | |
tft.setFreeFont(&Orbitron_Light_24); | |
tft.setTextColor(TFT_GREEN, TFT_BLACK); | |
tft.print("Button 2"); | |
tft.setCursor(0, 60); | |
tft.print("Pressed!"); | |
} | |
void setup() { | |
Serial.begin(9600); | |
pinMode(BUTTON1PIN, INPUT); | |
pinMode(BUTTON2PIN, INPUT); | |
attachInterrupt(BUTTON1PIN, toggleButton1, FALLING); | |
attachInterrupt(BUTTON2PIN, toggleButton2, FALLING); | |
Serial.println("Test"); | |
tft.begin(); | |
tft.setRotation(3); | |
// put your setup code here, to run once: | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
delay(3000); | |
tft.fillScreen(TFT_BLACK); | |
tft.setTextColor(TFT_GREEN, TFT_BLACK); | |
tft.setCursor(0, 30); | |
tft.setFreeFont(&Orbitron_Light_24); | |
tft.print("Press Button"); | |
tft.drawLine(0, 35, 250, 35, TFT_BLUE); | |
tft.setCursor(0, 60); | |
tft.print("3 Seconds Delay"); | |
Serial.println("serial line example"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works also with LilyGo T-Display-S3 but you have to #define BUTTON1PIN 14
Thanks for the share !