I'm using a Nano with a TFT display communicating via SPI. I'm trying to display the lyric's of a song. I'm using a switch case function to write each verse on the screen. I have a delay set for 2 seconds, every 2 seconds it should increment the switch case variable (verse_number).
When I run the code the time delay doesn't appear to be working and does not increment the variable, I have a Serial.print statement to monitor it. Halting the program may not be the correct term but it doesn't do anything. If I comment out the switch case statement then the time delay works and the variable increments.
I've used the switch case statement before, I've compared what I have to the previous project and checked the reference on it.
Probably doing something dumb but this dummy can't figure it out.
Here's the code
// mp3 player with TFT display
// Rev 1, display lyrics
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_HX8357.h"
// These are 'flexible' lines that can be changed
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8 // RST can be set to -1 if you tie it to Arduino's reset
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);
int verse_number = 0;
long int delay_time = millis();
long int test = 0;
void setup() {
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_HX8357.h"
Serial.begin(9600);
// These are 'flexible' lines that can be changed
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8 // RST can be set to -1 if you tie it to Arduino's reset
// Color definitions
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_HX8357 tft = Adafruit_HX8357(TFT_CS, TFT_DC, TFT_RST);
tft.begin();
tft.fillScreen(BLACK); //clears screen, sets to Black
tft.setRotation(3); // rotates screen 90' for landscape mode
} // end setup
void loop() {
// cycle through verses
// Verse delays
if ((millis() - delay_time) > 2000){
verse_number = verse_number + 1;
Serial.println(verse_number);
delay_time = millis();
} // end ((millis() - delay_time) > 2000)
switch (verse_number){
case 1:
tft.fillScreen(BLACK); //clears screen, sets to Black
tft.setCursor(10, 70);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Opening Screen");
Serial.println("case 1");
break;
case 2:
tft.fillScreen(BLACK); //clears screen, sets to Black
// Print verse 1
tft.setCursor(10, 70);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Every day is so wonderful");
tft.setCursor(10, 100);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Then suddenly it's hard to breathe");
tft.setCursor(10, 130);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Now and then I get insecure");
tft.setCursor(10, 160);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("From all the pain");
tft.setCursor(10, 190);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("I'm so ashamed");
break;
case 3:
tft.fillScreen(BLACK); //clears screen, sets to Black
// Print verse 2
tft.setCursor(10, 70);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("I am beautiful no matter what they say");
tft.setCursor(10, 100);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Words can't bring me down");
tft.setCursor(10, 130);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("I am beautiful in every single way");
tft.setCursor(10, 160);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Yes, words can't bring me down, oh no");
tft.setCursor(10, 190);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("So don't you bring me down today");
break;
default:
tft.fillScreen(BLACK); //clears screen, sets to Black
tft.setCursor(10, 70);
tft.setTextColor(WHITE);
tft.setTextSize(2);
tft.print("Ending Screen");
} // end switch
} // end loop
Thanks for any help
John