#include #include #define LEFT_BUTTON 0 #define RIGHT_BUTTON 14 #define RANDOM_LOWER_BOUND 0 #define RANDOM_UPPER_BOUND 100000 int randomNumber = 0; void rainbowStrobe(); TFT_eSPI tft = TFT_eSPI(); // Invoke library, void setup() { randomSeed(analogRead(1)); // Set a random seed randomNumber = random(RANDOM_LOWER_BOUND, RANDOM_UPPER_BOUND); //Generate a new random number Serial.begin(115200); // Setup serial monitor pinMode(LEFT_BUTTON, INPUT_PULLUP); pinMode(RIGHT_BUTTON, INPUT_PULLUP); Serial.println("Commencing screen colour pulse."); // Print message to serial monitor tft.init(); // Start the ESP32 screen tft.setRotation(3); //Set the ESP32 screen orientation tft.fillScreen(TFT_BLACK); //Set the screen to all black delay(1000); // Wait 1 second tft.fillScreen(TFT_RED); //Fill the screen red delay(1000); // Wait 1 second tft.fillScreen(TFT_GREEN); // Fill the screen green delay(1000); // Wait 1 second tft.fillScreen(TFT_BLUE); // Fill the screen blue delay(1000); // Wait 1 second tft.fillScreen(TFT_BLACK); // Set screen back to black Serial.println("Finished screen colour pulse."); // Print message to serial monitor } void loop() { bool left_button_pressed = !digitalRead(LEFT_BUTTON); bool right_button_pressed = !digitalRead(RIGHT_BUTTON); tft.fillRect(200, 0, 120, 50, TFT_BLACK); // Fill the dynamic part of the screen with black to clear it tft.setTextColor(TFT_WHITE); // Set text font colour tft.setTextSize(2); // Set text font size tft.setCursor(0, 0); // Set cursor to top left tft.print("Left button state: "); // Write text to LCD Screen tft.println(left_button_pressed); // Write text to LCD Screen tft.print("Right button state: "); // Write text to LCD Screen tft.println(right_button_pressed); // Write text to LCD Screen tft.print("Random number is: "); // Write text to LCD Screen tft.println(randomNumber); // Write text to LCD screen // If both buttons pressed simultaneously, do a rainbow strobe if (left_button_pressed && right_button_pressed) { rainbowStrobe(); } delay(100); // Sleep for 100 millisecods to keep FPS modest } void rainbowStrobe() { tft.fillScreen(TFT_WHITE); delay(300); tft.fillScreen(TFT_RED); delay(300); tft.fillScreen(TFT_ORANGE); delay(300); tft.fillScreen(TFT_YELLOW); delay(300); tft.fillScreen(TFT_GREEN); delay(300); tft.fillScreen(TFT_BLUE); delay(300); tft.fillScreen(TFT_PURPLE); delay(300); tft.fillScreen(TFT_VIOLET); delay(300); tft.fillScreen(TFT_BLACK); }