/* * Program: * 5_Wire_Read_01 * Created by: * Jonathon Weeks * On date: * 2018-10-22 * * Description: * This program is a state machine that waits for a button-press * before reading a coordinate pair from a 5-wire resisitve touch * panel. The coordinate pair is then sent to the computer via * Serial. * * Function: * State-machine blink's an LED * Plan: * Use button to blink LED * Use button to send message via Serial * Use button to read touch-panel * Send coordinates via Serial */ //~~~~~~~~ //~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Variables //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int temp; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // State variables //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int state; unsigned long state_time; #define STATE_START 0 #define WAIT_TIME 1000 void setup() { // initialize digital pin LED_BUILTIN as an output. pinMode(LED_BUILTIN, OUTPUT); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Initialize variables //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // State Machine state = STATE_START; } void loop() { switch(state) { case 0: // LED on // Turn on the LED digitalWrite(LED_BUILTIN, HIGH); // Record the time state_time = millis(); // Switch to the next state state = 1; break; case 1: // Wait // How long has it been since the LED was turned on? temp = millis() - state_time; // Has it been long enough? if (temp > WAIT_TIME) { // If it has... // Switch to the next state state = 2; } // Otherwise, do nothing. break; case 2: // LED off // Turn off the LED digitalWrite(LED_BUILTIN, LOW); // Record the time state_time = millis(); // Switch to the next state state = 3; break; case 3: // Wait // How long has it been since the LED was turned on? temp = millis() - state_time; // Has it been long enough? if (temp > WAIT_TIME) { // If it has... // Switch to the next state state = 0; } // Otherwise, do nothing. break; default: // Error break; } }