commit ccb0410c0553fd29be8ea780082a70c4e670abba Author: krishmo118 Date: Wed Feb 26 20:20:40 2025 +0000 Upload files to "/" Initial Commit diff --git a/gerLedArdFinal.ino b/gerLedArdFinal.ino new file mode 100644 index 0000000..fd3b89d --- /dev/null +++ b/gerLedArdFinal.ino @@ -0,0 +1,94 @@ +#include + +#include + +void buttonPressed(); + +// How many leds in your strip? +#define NUM_LEDS 300 + +//defining locations of pins +#define DATA_PIN 2 +#define BUTTON_PIN 4 + +// Define the array of leds +CRGB leds[NUM_LEDS]; + +//assigning locations of pins +int buttonPin = 4; +int ledPin = 13; + +//file object to store csv +//File dataFile; + +unsigned volatile long buttonPressTime = millis(); +bool volatile buttonFlag = false; + +void buttonPressed() { + unsigned long current = millis(); + + if(buttonPressTime + 100 < current){ + buttonFlag = true; + buttonPressTime = current; + } +} + +void setup() { + + FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is assumed + Serial.begin(9600); + pinMode(BUTTON_PIN, INPUT_PULLUP); //use internal pullup resistor + attachInterrupt(buttonPin, buttonPressed, FALLING); + +} //void setup + +int maxRounds = 5; // max loop +int roundCounter = 0; // initialized counter + +double loopDelay = 1; +int correctLED = 88; +unsigned long startTime = 0; +unsigned long loopTime = 0; +unsigned long correctTime = 0; + + +void loop() { + 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) { + // Program is effectively stopped here + } + //return; // Exit the loop function and stop further execution + } + + 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); + delayMicroseconds(loopDelay); + leds[i] = CRGB::Black; + if (i == correctLED) correctTime = millis(); + FastLED.show(); + } + + if (buttonFlag) { + long timeDiff = correctTime - buttonPressTime; + if (abs(timeDiff) < 10){ + Serial.println("Perfect timing!"); + Serial.println(correctTime); + } else if (timeDiff > 0) { + Serial.print("Too early! Time difference: "); + Serial.println(correctTime - buttonPressTime); + } else if (timeDiff < 0) { + Serial.print("Too late! Time difference: "); + Serial.println(buttonPressTime - correctTime); + } + buttonFlag = false; + } + + roundCounter++; + } //loop \ No newline at end of file