#include #define APA102_USE_FAST_GPIO #include const int HALL_PIN = 2; const int ROUND_COUNT = 2; // Define which pins to use. const uint8_t dataPin = 10; const uint8_t clockPin = 11; // Create an object for writing to the LED strip. APA102 ledStrip; const uint16_t ledCount = 56; const uint8_t brightness = 1; const rgb_color RED = rgb_color(255, 0, 0); const rgb_color GREEN = rgb_color(0, 255, 0); const rgb_color BLUE = rgb_color(0, 0, 255); const rgb_color WHITE = rgb_color(255, 255, 255); const int state_count = 4; rgb_color colors[ledCount]; float passed = 0; int state = 0; void setup() { Serial.begin(115200); pinMode(HALL_PIN, INPUT); } void loop() { float start = micros(); int count = 0; bool change = false; while (count < ROUND_COUNT) { if (digitalRead(HALL_PIN) == LOW) { if (!change) { change = true; count++; } } else { change = false; } float current_diff = micros() - start; for (int i = 0; i < state_count; i++) { if (current_diff > ((passed / state_count) * i)) { state = i; } } rgb_color color = WHITE; switch (state) { case 1: color = RED; break; case 2: color = GREEN; break; case 3: color = BLUE; break; } for (uint16_t i = 0; i < ledCount; i++) { colors[i] = color; } ledStrip.write(colors, ledCount, brightness); } passed = (micros() - start); }