//################################## BEGIN INCLUDES ################################## #include #include #ifdef __AVR__ #include // Required for 16 MHz Adafruit Trinket #include // for noise reduction #endif //################################### END INCLUDES ################################### //################################### BEGIN DEFINES ################################## #define LED_PIN 6 //set the data pin of the led strip #define LED_COUNT 10 //set the number of leds #define NUM_BUTTONS 10 //set the number of buttons #define BRIGHTNESS 25 //set the led brightness (max = 255, good = 125) //the power switch pin const int powerSwitch = 15; //the power switch led pin const int pswLED = A0; //the status of the power switch; //true = on, false = off static bool power; //#################################### END DEFINES ################################### //############################## BEGIN INITIALIZATIONS ############################### //define the led strip object Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); //the pins for all of the buttons const int buttonInputs[NUM_BUTTONS] = {2, 3, 4, 5, 7, 8, 9, 10, 16, 14}; //the states of all of the buttons int buttonStates[NUM_BUTTONS] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //whether or not this led should be ignored for the idle wave effect (i.e. it is being set by the flash function) bool ignore[LED_COUNT] = {false, false, false, false, false, false, false, false, false, false}; //initialize the TaskScheduler object Scheduler runner; //############################### END INITIALIZATIONS ################################ //################################# BEGIN FUNCTIONS ################################## //called by taskscheduler void readPswCallback(){ //read the status of the power switch digitally int powerStatus = digitalRead(powerSwitch); if(powerStatus == HIGH){ power = true; digitalWrite(pswLED, LOW); //when device on, psw led off } else{ power = false; digitalWrite(pswLED, HIGH); //when device off, psw led on //turn off leds and update the led strip strip.clear(); strip.show(); //adc low power mode sleep_mode(); } } //reads serial communications from the computer which contains data on which led/button to flash/ignore void readSerial() { //buffer to hold incoming data static String buffer = ""; while (Serial.available() > 0) { //read one character at a time char incoming = Serial.read(); if (incoming == '\n') { //reached end of message //process the full message parseSerial(buffer); //clear the buffer for the next message buffer = ""; } else { //append character to buffer buffer += incoming; } } } //helper function for readSerial(); //updates the arrays 'buttonStates' and 'ignore' void parseSerial(const String& data) { int idx = 0; for (int i = 0; i < data.length() && idx < NUM_BUTTONS; i++) { if (data[i] == '0') { buttonStates[idx] = 0; ignore[idx] = false; idx++; } else if (data[i] == '1') { buttonStates[idx] = 1; ignore[idx] = true; idx++; } } } //called by taskscheduler void flashTaskCallback(){ if(!power) return; static bool cycle[NUM_BUTTONS] = {false, false, false, false, false, false, false, false, false, false}; for(int i = 0; i