#include #include #define NUM_LEDS 300 // How many leds in your strip? //defining locations of pins #define DATA_PIN 2 #define BUTTON_PIN 4 //should eventually change to be a value input //file object to store csv //File dataFile; int roundCounter = 1; //# of rounds to be iterated on int correctLED = 88; //an arbitrary number int maxRounds = 5; int mode; //The mode the user wants to do int lightOn = 50; // time light will be on in mode 2 double loopDelay = 1.0; unsigned long correctTime = 0; unsigned long reactionTime = 0; unsigned long startTime = 0; unsigned long loopTime = 0; volatile bool buttonFlag = false; // idk unsigned volatile long buttonPressTime = millis(); // idk //variable test unsigned int randomLED; //random LED ranging from 0 - 299 unsigned long variableStartTime = 0; unsigned long variableEndTime = 0; unsigned long variableTotalTime; float convertedTime; // od work int numTests; // evaluate utility unsigned char counter = 0; // evaluate utility String color = String("Red"); //Let the user eventually set the color //perhpas a pinproblem CRGB leds[NUM_LEDS]; // Define the array of leds void buttonPressed() { unsigned long current = millis(); // change perhaps if(buttonPressTime + 100 < current) { buttonFlag = true; buttonPressTime = current; } // if } // buttonPressed void printPressed(int counter, long delayed, long diff, long correct) { if (abs(diff) < 10){ Serial.println("Perfect timing!"); Serial.println(counter, delayed, correct); } else if (diff > 0) { Serial.print("Too early! Time difference: "); Serial.println(counter, delayed, abs(diff)); } else if (diff < 0) { Serial.print("Too late! Time difference: "); Serial.println(counter, delayed, abs(diff)); } // if - else buttonFlag = false; } // printPressed void setup() { FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is assumed Serial.begin(115200); pinMode(BUTTON_PIN, INPUT_PULLUP); //use internal pullup resistor randomSeed(analogRead(0)); //make sure analog pin 0 is't connected!!! attachInterrupt(buttonPin, buttonPressed, FALLING); Serial.println("Which mode would you like to run?"); Serial.println("1 - CAT"); Serial.println("2 - Fixed Reaction Time"); Serial.println("3 - Variable Reaction Time"); Serial.println("4 - Whack - A - Mole"); Serial.print("Enter Mode Number:"); while (Serial.available() == 0) { } //maybe "if" mode = Serial.parseInt(); //error handling for if improper string entered Serial.println(""); Serial.println(""); } // setup //assumes mode = 1 void catLoop() { if (roundCounter > maxRounds) { fill_solid(leds, NUM_LEDS, CRGB::Black); // turn LEDs off FastLED.show(); Serial.println("Max rounds reached. Stopping program."); while (true) { // Program is effectively stopped here } // while return; // Exit the loop function and stop further execution } // if for (int i = 0; i < NUM_LEDS; i++) { //turns light on to white, delays, turns it off(black) leds[i] = CRGB::White; FastLED.show(); //delay(loopDelay); // i kept this delayMicroseconds(loopDelay); leds[i] = CRGB::Black; if (i == correctLED) { correctTime = millis(); FastLED.show(); //idk here the cod was missing parenthesis } // if if (buttonFlag) { // button press output unsigned long timeDiff = correctTime - buttonPressTime; printPressed(roundCounter, loopDelay, timeDiff, correctTime); } // if roundCounter++; } // for } // catLoop //assumes mode = 2 void fixedRxnTime() { if (roundCounter > maxRounds - 1) { fill_solid(leds, NUM_LEDS, CRGB::Black); // turn LEDs off FastLED.show(); Serial.println("Max rounds reached. Stopping program."); while (true) { //wouldn't this never run anything then? infinite loop // Program is effectively stopped here } // while return; // Exit the loop function and stop further execution } // checks for running completion if //turns light on to white, delays, turns it off(black) leds[correctLED] = CRGB::White; FastLED.show(); correctTime = millis(); delay(lightOn); leds[correctLED] = CRGB::Black; FastLED.show(); delayMicroseconds(loopDelay); if (!buttonFlag) { Serial.println("Button missed"); } else { unsigned long timeDiff = correctTime - buttonPressTime; printPressed(roundCounter, loopdelay, timeDiff, correctTime); } // button press output } // if } //fixedRxnTime //assumes mode = 3 void variableRxnTime() { FastLED.setBrightness(50); //50 is uint8_t - unsigned 8 bit int (0-255) while (counter != numTests) { Serial.println("Press when ready"); while (digitalRead(BUTTON_PIN) == HIGH) { } // waits until the user presses the button } // while while (digitalRead(BUTTON_PIN) == HIGH) { } // waits until the user presses the button - change delay(3000); randomLED = random(300); Serial.println(randomLED); //prints to the terminal the random LED index for testing leds[randomLED] = CRGB::color; FastLED.show(); startTime = millis(); while (digitalRead(BUTTON_PIN) == HIGH) { } endTime = millis(); delay(3000); leds[randomLED] = CRBG::Black; //turns the LED off FastLED.show(); variableTotalTime = (variableEndTime - variableStartTime); Serial.print("Your reaction time was: "); Serial.print(convertedTime); Serial.println(" seconds!"); startTime = 0; endTime = 0; counter++; } void loop() { switch (mode) { case 1: catLoop(); break; case 2: fixedRxnTime(); break; case 3: variableRxnTime(); break; } } // loop //remove a round if not used