#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
// --- PIN CONFIGURATION (Matches your latest diagram.json) ---
#define TFT_CS 20 // Brown wire
#define TFT_DC 21 // Gold wire
#define TFT_RST 15 // Orange wire
#define SWITCH_PIN 4 // Matches your move to GP4
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// --- MADDEN BITMAP DATA (128x160) ---
// This array must have exactly 2560 bytes for a 128x160 image.
const unsigned char madden_bitmap[] PROGMEM = {
// PASTE YOUR FULL HEX DATA HERE
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xfc, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x0f, 0xff, 0xff,
0xff, 0xff, 0xff, 0xf8, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x07, 0xff, 0xff,
0xff, 0xff, 0xff, 0xf0, 0x00, 0xf1, 0xc7, 0x1c, 0x71, 0xc7, 0x1c, 0x7c, 0x00, 0x03, 0xff, 0xff,
0xff, 0xff, 0xff, 0xe0, 0x00, 0xf1, 0xc7, 0x1c, 0x71, 0xc7, 0x1c, 0x7c, 0x00, 0x01, 0xff, 0xff,
0xff, 0xff, 0xff, 0xc0, 0x00, 0xf1, 0xc7, 0x1c, 0x71, 0xc7, 0x1c, 0x7c, 0x00, 0x01, 0xff, 0xff,
0xff, 0xff, 0xff, 0x80, 0x00, 0xf1, 0xc7, 0x1c, 0x71, 0xc7, 0x1c, 0x7c, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff,
0xff, 0xff, 0xfe, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xff,
0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xff,
0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x01, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff,
0xff, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xff,
0xff, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff,
0xff, 0xff, 0xc0, 0x00, 0x00, 0x01, 0xff, 0xff, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff,
0xff, 0xff, 0x80, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
0xff, 0xff, 0x00, 0x00, 0x00, 0x1f, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f,
0xff, 0xfe, 0x00, 0x00, 0x00, 0x3f, 0xfc, 0x1f, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
};
bool isMaddenOn = false;
int lastSwitchState = -1;
void setup() {
Serial.begin(115200);
pinMode(SWITCH_PIN, INPUT_PULLUP);
tft.begin();
// Using Rotation 0 for the 128x160 vertical bitmap
tft.setRotation(0);
tft.fillScreen(ILI9341_BLACK);
updateDisplay();
}
void loop() {
int currentReading = digitalRead(SWITCH_PIN);
// Redraw only when the switch changes
if (currentReading != lastSwitchState) {
isMaddenOn = (currentReading == LOW);
updateDisplay();
// Debug info
if(isMaddenOn) Serial.println("Madden: ON");
else Serial.println("Madden: OFF");
lastSwitchState = currentReading;
delay(50); // Debounce
}
}
void updateDisplay() {
tft.fillScreen(ILI9341_BLACK);
if (isMaddenOn) {
// Center the 128x160 bitmap on the 240x320 screen
// X: (240-128)/2 = 56 | Y: (320-160)/2 = 80
tft.drawBitmap(56, 80, madden_bitmap, 128, 160, ILI9341_WHITE);
} else {
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.setCursor(45, 130);
tft.print("FLIP THE");
tft.setCursor(65, 165);
tft.print("SWITCH");
}
}