#include #include #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define SCREEN_ADDRESS 0x3C // 0x3D or 0x3C depending on brand Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1, 1700000UL, 1700000UL); #define PIN_LED 15 //The LED is at pin 15 #define N_TOUCH 6 // I have 6 touchpads #define THRESHOLD 500 //Above this number, the touchpad is touched, below not //Q touch peripherals uint8_t touch_pins[N_TOUCH] = {2, 3, 4, 5, 6, 7}; Adafruit_FreeTouch* touch_devices[N_TOUCH]; //touch state int touch_values[N_TOUCH] = {0,0,0,0,0,0}; bool pin_touched_now[N_TOUCH] = {false, false, false, false, false, false}; bool pin_touched_past[N_TOUCH] = {false, false, false, false, false, false}; int circuitChoice = 1; //tracking sensory data void update_touch() { Ptc *ptc = ((Ptc *)PTC); for (int i = 0; i < N_TOUCH; i++) { // start touch_devices[i]->begin(); // read touch_values[i] = touch_devices[i]->measure(); // reset ptc->CTRLA.bit.ENABLE = 0; ptc->CTRLA.bit.SWRESET = 1; // update the state pin_touched_past[i] = pin_touched_now[i]; pin_touched_now[i] = touch_values[i] > THRESHOLD; } } //home void setup() { // initialize Serial port Serial.begin(0); // initialize capacitive touch peripherals for (int i = 0; i < N_TOUCH; i++) { touch_devices[i] = new Adafruit_FreeTouch(touch_pins[i], OVERSAMPLE_1, RESISTOR_100K, FREQ_MODE_NONE); } // give the screen some time to power up delay(50); // initialize display display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); display.clearDisplay(); // home screen display.setTextColor(SSD1306_WHITE); display.setTextSize(2); display.setCursor (35, 10); display.print("START"); display. setCursor (4, 30); display.print("GRAND PRIX"); display.setTextSize(1); display. setCursor (4, 55); display.print("Press Q0 to continue"); display.display(); // LED setup pinMode(PIN_LED, OUTPUT); digitalWrite(PIN_LED, LOW); } void drawMenu() { display.clearDisplay(); display.setTextSize(1); display. setCursor (4, 10); display.setTextColor(SSD1306_WHITE); display.print("Select Circuit:"); display.display(); const char* circuits[] = {"Hungaroring(Easy)", "Silverstone(Medium)", "Baku(Hard)"}; for (int i = 0; i < 6; i++) { if (circuitChoice == i + 1) { display.setTextSize(1); display.setCursor(0, 30 + i*12); display.print("> "); } else { display.setTextSize(1); display.setCursor(0, 30 + i*12); display.print(" "); } display.print(circuits[i]); } display.display(); } void loop() { // update the touch sensors update_touch(); // button 0 was just pressed, show menu if (pin_touched_now[0] && !pin_touched_past[0]) { drawMenu(); } // button 5 was just pressed, scroll down if (pin_touched_now[5] && !pin_touched_past[5]) { circuitChoice--; if (circuitChoice < 1) circuitChoice = 3; drawMenu(); } // button 2 was just pressed, scroll up if (pin_touched_now[2] && !pin_touched_past[2]) { circuitChoice++; if (circuitChoice > 3) circuitChoice = 1; drawMenu(); } }