diff --git a/FredLightingCopy.ino b/FredLightingCopy.ino index de859f4..332424b 100644 --- a/FredLightingCopy.ino +++ b/FredLightingCopy.ino @@ -1,145 +1,93 @@ -//Absolute version on the collar as of 3-24-2026! +// Final "Halt on Press" Version - 3-19-2026 #include #define PIN 3 #define NUM_OF_LEDS 56 -Adafruit_NeoPixel strip = Adafruit_NeoPixel(56, PIN, NEO_GRB + NEO_KHZ800); - - -int randomNumber; -int red[56]; -int green[56]; -int blue[56]; - int sensorPin = A0; - int sensorValue = 0; - int select = 0; - int i,j; - int element[8][3]; +Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_OF_LEDS, PIN, NEO_GRB + NEO_KHZ800); +int red[56], green[56], blue[56]; +int sensorPin = A0; +int select = 0; void setup() { - // put your setup code here, to run once: - strip.begin(); - strip.show(); // Initialize all pixels to 'off' - - - randomSeed(analogRead(A1)); + strip.begin(); + strip.setBrightness(140); + strip.show(); + randomSeed(analogRead(A1)); } -boolean check(){ - boolean change = false; - int sensorValue=analogRead(sensorPin); - if (sensorValue < 512) {select++; change = true;} - if (select > 4) select = 0; - delay(67); - return change; +// This function now only handles the MODE SWAP after release +boolean check() { + if (analogRead(sensorPin) < 512) { + // Wait until released + while (analogRead(sensorPin) < 512) { + delay(10); + } + + // Advance mode + select++; + if (select > 4) select = 0; + + delay(50); // Small debounce + return true; + } + return false; } - - -void clearStrip(){ - for (int i = 0; i < NUM_OF_LEDS; i++){ - strip.setPixelColor(i, 0, 0, 0); +void clearStrip() { + for (int k = 0; k < NUM_OF_LEDS; k++) { + strip.setPixelColor(k, 0, 0, 0); } strip.show(); } -void greenChaserTask(int i){ +void greenChaserTask(int i) { int chaser_len = 5; - strip.setPixelColor(i, 0, 125, 0); - - if (i < chaser_len) { - - strip.setPixelColor((i-chaser_len+56)%56, 0, 0, 0); - - } - - strip.setPixelColor(i-chaser_len, 0, 0, 0); - strip.setBrightness(140); + // Modulo prevents negative index crashes + strip.setPixelColor((i - chaser_len + NUM_OF_LEDS) % NUM_OF_LEDS, 0, 0, 0); strip.show(); } -void randomLightsTask(int i){ - if (i == 0){ +void randomLightsTask(int i) { + if (i == 0) { for (int r = 0; r < 56; r++) { - red[r] = random(255); - } - - for (int g = 0; g < 56; g++) { - green[g] = random(255); - } - - for (int b = 0; b < 56; b++) { - blue[b] = random(255); + red[r] = random(255); + green[r] = random(255); + blue[r] = random(255); } } - strip.setPixelColor(i, red[i], green[i], blue[i]); - - for (int r = 0; r < 56; r++) { - red[r] -= 4; - } - - for (int g = 0; g < 56; g++) { - green[g] -= 4; + for (int k = 0; k < 56; k++) { + if(red[k] > 4) red[k] -= 4; + if(green[k] > 4) green[k] -= 4; + if(blue[k] > 4) blue[k] -= 4; } - - for (int b = 0; b < 56; b++) { - blue[b] -= 4; - } - - strip.setBrightness(140); strip.show(); } -void colorBandTask(int i, int r, int g, int b){ - strip.setPixelColor(i, r, g, b); - strip.setBrightness(140); - strip.show(); -} - -void greenBandTask(int i){ - colorBandTask(i, 0, 255, 0); -} - -void redBandTask(int i){ - colorBandTask(i, 255, 0, 0); -} - -void blueBandTask(int i){ - colorBandTask(i, 0, 0, 255); +void colorBandTask(int i, int r, int g, int b) { + strip.setPixelColor(i, r, g, b); + strip.show(); } - void loop() { - // put your main code here, to run repeatedly: - - /* Read Sensor - Sensor value will be 1023 when open, - will drop to 78 when blocked - When sensor is blocked, advance slection by 1*/ - - /* ALL GREEN */ + for (int i = 0; i < NUM_OF_LEDS; i++) { + + // 1. Check for the press (and hold here) + if (check()) { + clearStrip(); + break; // Exit 'for' loop to start next animation + } - for (i = 0; i < NUM_OF_LEDS; i ++){ + // 2. Run animations ONLY if sensor isn't being held if (select == 0) greenChaserTask(i); else if (select == 1) randomLightsTask(i); - else if (select == 2) greenBandTask(i); - else if (select == 3) blueBandTask(i); - else if (select == 4) redBandTask(i); - if (check()) {clearStrip(); break;} - delay(20); - } - + else if (select == 2) colorBandTask(i, 0, 255, 0); // Green + else if (select == 3) colorBandTask(i, 0, 0, 255); // Blue + else if (select == 4) colorBandTask(i, 255, 0, 0); // Red + + delay(18); } - - - - - - - - -int cigarettes = 500; +}