Hello,
I am trying to build a device that will play different animations on a TFT screen, where each animation is tied to its own specific DIP switch.
I'm super new to working with LCD's so if anyone has any tips or suggestions for resources that could help me with this I would really appreciate it.
Thanks.
EDIT
I have this 2.8" TFT by Elegoo.
I am using a Arduino MEGA and also have an UNO just in case. I've been experimenting with the examples from the Adafruit TFTLCD Library, mainly the Example_Graphic_Code.ino.
I can't upload the code because I'm a new user.
Basically, I want to have little animations like the ones in the example code, but I want them to be triggered by the activation of certain DIP switches, with one default animation playing when none of them are activated.
This is the example code.
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Adafruit_TFTLCD tft;
void setup(void) {
Serial.begin(9600);
Serial.println(F("TFT LCD test"));
#ifdef USE_ADAFRUIT_SHIELD_PINOUT
Serial.println(F("Using Adafruit 2.8\" TFT Arduino Shield Pinout"));
#else
Serial.println(F("Using Adafruit 2.8\" TFT Breakout Board Pinout"));
#endif
Serial.print("TFT size is "); Serial.print(tft.width()); Serial.print("x"); Serial.println(tft.height());
tft.reset();
uint16_t identifier = tft.readID();
if(identifier == 0x9325) {
Serial.println(F("Found ILI9325 LCD driver"));
} else if(identifier == 0x9328) {
Serial.println(F("Found ILI9328 LCD driver"));
} else if(identifier == 0x7575) {
Serial.println(F("Found HX8347G LCD driver"));
} else if(identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
} else if(identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"));
} else {
Serial.print(F("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT"));
Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
Serial.println(F("If using the breakout board, it should NOT be #defined!"));
Serial.println(F("Also if using the breakout, double-check that all wiring"));
Serial.println(F("matches the tutorial."));
return;
}
tft.begin(identifier);
Serial.println(F("Benchmark Time (microseconds)"));
Serial.print(F("Screen fill "));
Serial.println(testText());
delay(500);
Serial.println(F("Done!"));
}
void loop(void) {
for(uint8_t rotation=0; rotation<4; rotation++) {
tft.setRotation(rotation);
testText();
delay(2000);
}
}
unsigned long testText() {
tft.fillScreen(BLACK);
unsigned long start = micros();
tft.setCursor(0, 0);
tft.setTextColor(WHITE); tft.setTextSize(5);
tft.println("Nice Work!");
tft.setTextColor(YELLOW); tft.setTextSize(2);
tft.println("You played...");
tft.println("'Insert Chord Here' ");
tft.setTextSize(2);
tft.println("Keep it up!");
return micros() - start;
}
This is the code I plan on tying the animations to
// #define NOTE_C4 262
//#define NOTE_Csharp4 277
//#define NOTE_D4 294
//#define NOTE_Dsharp4 311
////#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_Fsharp4 370
#define NOTE_G4 392
#define NOTE_Gsharp4 415
#define NOTE_A4 440
#define NOTE_Asharp4 466
#define NOTE_B4 493
#define NOTE_C5 523
#define NOTE_Csharp5 554
#define NOTE_D5 587
#define NOTE_Dsharp5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_Fsharp5 740
#define NOTE_G5 784
#define NOTE_Gsharp5 831
#define NOTE_A5 880
#define NOTE_Asharp5 932
#define NOTE_B5 988
#define NOTE_C6 1046
#define NOTE_Csharp6 1109
#define NOTE_D6 1175
#define NOTE_Dsharp6 1245
#define NOTE_E6 1319
#define ACTIVATED LOW
const int LED_C4 = 2;
const int LED_D4 = 1;
//const int LED_E
//const int LED_F
//const int LED_G
//const int LED_A
//const int LED_B
//const int LED_C5
const int PIEZO = 2;
const int LED = 3;
const int BUTTON_F4 = 53;
const int LED_F4 = 29;
const int BUTTON_Fsharp4 = 6;
const int LED_Fsharp4 = 27;
const int BUTTON_G4 = 51;
const int BUTTON_Gsharp4 = 7;
const int BUTTON_A4 = 49;
const int BUTTON_Asharp4 = 8;
const int BUTTON_B4 = 47;
const int BUTTON_C5 = 45;
const int BUTTON_Csharp5 = 9;
const int BUTTON_D5 = 52;
const int BUTTON_Dsharp5 = 11;
const int BUTTON_E5 = 50;
const int BUTTON_F5 = 48;
const int BUTTON_Fsharp5 = 12;
const int BUTTON_G5 = 46;
const int BUTTON_Gsharp5 = 13;
const int BUTTON_A5 = 44;
const int BUTTON_Asharp5 = 45;
const int BUTTON_B5 = 42;
const int BUTTON_C6 = 29;
const int BUTTON_Csharp6 = 42;
const int BUTTON_D6 = 26;
const int BUTTON_Dsharp6 = 41;
const int BUTTON_E6 = 27;
/*
const int BUTTON_F4 = 38;
const int BUTTON_Fsharp4 = 52;
const int BUTTON_G4 = 39;
const int BUTTON_Gsharp4 = 53;
const int BUTTON_A4 = 36;
const int BUTTON_Asharp4 = 50;
const int BUTTON_B4 = 37;
const int BUTTON_C5 = 34;
const int BUTTON_Csharp5 = 51;
const int BUTTON_D5 = 35;
const int BUTTON_Dsharp5 = 46;
const int BUTTON_E5 = 32;
const int BUTTON_F5 = 33;
const int BUTTON_Fsharp5 = 47;
const int BUTTON_G5 = 30;
const int BUTTON_Gsharp5 = 44;
const int BUTTON_A5 = 31;
const int BUTTON_Asharp5 = 45;
const int BUTTON_B5 = 28;
const int BUTTON_C6 = 29;
const int BUTTON_Csharp6 = 42;
const int BUTTON_D6 = 26;
const int BUTTON_Dsharp6 = 41;
const int BUTTON_E6 = 27;
*/
void setup()
{
pinMode(LED, OUTPUT);
//pinMode(BUTTON_C4, INPUT);
// digitalWrite(BUTTON_C4,HIGH);
// pinMode(BUTTON_D4, INPUT);
//digitalWrite(BUTTON_D4,HIGH);
// pinMode(BUTTON_E4, INPUT);
// digitalWrite(BUTTON_E4,HIGH);
pinMode(BUTTON_F4, INPUT);
digitalWrite(BUTTON_F4,HIGH);
pinMode(BUTTON_Fsharp4, INPUT);
digitalWrite(BUTTON_Fsharp4,HIGH);
pinMode(BUTTON_G4, INPUT);
digitalWrite(BUTTON_G4,HIGH);
pinMode(BUTTON_Gsharp4, INPUT);
digitalWrite(BUTTON_Gsharp4,HIGH);
pinMode(BUTTON_A4, INPUT);
digitalWrite(BUTTON_A4,HIGH);
pinMode(BUTTON_Asharp4, INPUT);
digitalWrite(BUTTON_Asharp4,HIGH);
pinMode(BUTTON_B4, INPUT);
digitalWrite(BUTTON_B4,HIGH);
pinMode(BUTTON_C5, INPUT);
digitalWrite(BUTTON_C5,HIGH);
pinMode(BUTTON_Csharp5, INPUT);
digitalWrite(BUTTON_Csharp5,HIGH);
pinMode(BUTTON_D5, INPUT);
digitalWrite(BUTTON_D5,HIGH);
pinMode(BUTTON_Dsharp5, INPUT);
digitalWrite(BUTTON_Dsharp5,HIGH);
pinMode(BUTTON_E5, INPUT);
digitalWrite(BUTTON_E5,HIGH);
pinMode(BUTTON_F5, INPUT);
digitalWrite(BUTTON_F5,HIGH);
pinMode(BUTTON_Fsharp5, INPUT);
digitalWrite(BUTTON_Fsharp5,HIGH);
pinMode(BUTTON_G5, INPUT);
digitalWrite(BUTTON_G5,HIGH);
pinMode(BUTTON_Gsharp5, INPUT);
digitalWrite(BUTTON_Gsharp5,HIGH);
pinMode(BUTTON_A5, INPUT);
digitalWrite(BUTTON_A5,HIGH);
pinMode(BUTTON_Asharp5, INPUT);
digitalWrite(BUTTON_Asharp5,HIGH);
pinMode(BUTTON_B5, INPUT);
digitalWrite(BUTTON_B5,HIGH);
pinMode(BUTTON_C6, INPUT);
digitalWrite(BUTTON_C6,HIGH);
pinMode(BUTTON_Csharp6, INPUT);
digitalWrite(BUTTON_Csharp6,HIGH);
pinMode(BUTTON_D6, INPUT);
digitalWrite(BUTTON_D6,HIGH);
pinMode(BUTTON_Dsharp6, INPUT);
digitalWrite(BUTTON_Dsharp6,HIGH);
pinMode(BUTTON_E6, INPUT);
digitalWrite(BUTTON_E6,HIGH);
digitalWrite(LED,LOW);
}
void loop()
{
while(digitalRead(BUTTON_F4) == ACTIVATED)
{
tone(PIEZO,NOTE_F4);
digitalWrite(LED_F4,HIGH);
}
if(digitalRead(BUTTON_Fsharp4) == ACTIVATED)
{
tone(PIEZO,NOTE_Fsharp4);
digitalWrite(LED_Fsharp4,HIGH);
}
else
{
digitalWrite(LED_Fsharp4,LOW);
}
while(digitalRead(BUTTON_G4) == ACTIVATED)
{
tone(PIEZO,NOTE_G4);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_Gsharp4) == ACTIVATED)
{
tone(PIEZO,NOTE_Gsharp4);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_A4) == ACTIVATED)
{
tone(PIEZO,NOTE_A4);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_Asharp4) == ACTIVATED)
{
tone(PIEZO,NOTE_Asharp4);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_B4) == ACTIVATED)
{
tone(PIEZO,NOTE_B4);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_C5) == ACTIVATED)
{
tone(PIEZO,NOTE_C5);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_Csharp5) == ACTIVATED)
{
tone(PIEZO,NOTE_Csharp5);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_D5) == ACTIVATED)
{
tone(PIEZO,NOTE_D5);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_Dsharp5) == ACTIVATED)
{
tone(PIEZO,NOTE_Dsharp5);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_E5) == ACTIVATED)
{
tone(PIEZO,NOTE_E5);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_F5) == ACTIVATED)
{
tone(PIEZO,NOTE_F5);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_Fsharp5) == ACTIVATED)
{
tone(PIEZO,NOTE_Fsharp5);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_G5) == ACTIVATED)
{
tone(PIEZO,NOTE_G5);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_Gsharp5) == ACTIVATED)
{
tone(PIEZO,NOTE_Gsharp5);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_A5) == ACTIVATED)
{
tone(PIEZO,NOTE_A5);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_Asharp5) == ACTIVATED)
{
tone(PIEZO,NOTE_Asharp5);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_B5) == ACTIVATED)
{
tone(PIEZO,NOTE_B5);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_C6) == ACTIVATED)
{
tone(PIEZO,NOTE_C6);
digitalWrite(LED,HIGH);
}
while(digitalRead(BUTTON_Csharp6) == ACTIVATED)
{
tone(PIEZO,NOTE_Csharp6);
digitalWrite(LED,HIGH);
}
noTone(PIEZO);
digitalWrite(LED,LOW);
}