#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <Fonts/FreeSerif12pt7b.h>
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10
#define BUTTON_PIN 4
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
int lastState = HIGH;
void setup() {
Serial.begin(9600);
Serial.println("Race Starting");
pinMode(BUTTON_PIN, INPUT_PULLUP);
tft.begin();
tft.setFont(&FreeSerif12pt7b);
// read diagnostics (optional but can help debug problems)
// uint8_t x = tft.readcommand8(ILI9341_RDMODE);
// Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
// x = tft.readcommand8(ILI9341_RDMADCTL);
// Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
// x = tft.readcommand8(ILI9341_RDPIXFMT);
// Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
// x = tft.readcommand8(ILI9341_RDIMGFMT);
// Serial.print("Image Format: 0x"); Serial.println(x, HEX);
// x = tft.readcommand8(ILI9341_RDSELFDIAG);
// Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
}
void loop(void) {
int value = digitalRead((BUTTON_PIN));
if (lastState != value) {
lastState = value;
if (value == HIGH) {
Serial.println(testFilledCircles(13, ILI9341_MAGENTA));
}
delay(1000);
}
tft.setCursor(40, 30);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(2);
tft.setRotation(1);
tft.println("Lane Yellow");
}
unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
unsigned long start;
int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
tft.fillScreen(ILI9341_BLACK);
start = micros();
for(x=(w/10); x<w; x+=(w/5)) {
for(y=(h/6); y<h; y+=(h/3)) {
tft.fillCircle(x, y, radius, ILI9341_RED);
}
delay(1000);
}
delay(1000);
for(x=(w/10); x<w; x+=(w/5)) {
for(y=(h/6); y<h; y+=(h/3)) {
tft.fillCircle(x, y, radius, ILI9341_GREEN);
}
}
delay(2000);
tft.fillScreen(ILI9341_BLACK);
return micros() - start;
}