Skip to content

Commit bd9a18b

Browse files
authored
Merge pull request #2 from gecko45812/patch-1
Update FredLightingCopy.ino
2 parents 11c3cfd + 38fa018 commit bd9a18b

1 file changed

Lines changed: 53 additions & 112 deletions

File tree

FredLightingCopy.ino

Lines changed: 53 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,93 @@
1-
//Current version on the collar as of 3-19-2026!
1+
// Final "Halt on Press" Version - 3-19-2026
22
#include <Adafruit_NeoPixel.h>
33

44
#define PIN 3
55
#define NUM_OF_LEDS 56
66

7-
Adafruit_NeoPixel strip = Adafruit_NeoPixel(56, PIN, NEO_GRB + NEO_KHZ800);
7+
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_OF_LEDS, PIN, NEO_GRB + NEO_KHZ800);
88

9-
10-
int randomNumber;
11-
int red[56];
12-
int green[56];
13-
int blue[56];
14-
int sensorPin = A0;
15-
int sensorValue = 0;
16-
int select = 0;
17-
int i,j;
18-
int element[8][3];
19-
boolean change;
9+
int red[56], green[56], blue[56];
10+
int sensorPin = A0;
11+
int select = 0;
2012

2113
void setup() {
22-
// put your setup code here, to run once:
23-
strip.begin();
24-
strip.show(); // Initialize all pixels to 'off'
25-
change = false;
26-
27-
28-
randomSeed(analogRead(A1));
14+
strip.begin();
15+
strip.setBrightness(140);
16+
strip.show();
17+
randomSeed(analogRead(A1));
2918
}
3019

31-
boolean check(){
32-
int sensorValue=analogRead(sensorPin);
33-
if (sensorValue < 512 && !change) {
34-
change = true;
20+
// This function now only handles the MODE SWAP after release
21+
boolean check() {
22+
if (analogRead(sensorPin) < 512) {
23+
// Wait until released
24+
while (analogRead(sensorPin) < 512) {
25+
delay(10);
26+
}
27+
28+
// Advance mode
3529
select++;
36-
} else {
37-
38-
change = false;
30+
if (select > 4) select = 0;
3931

32+
delay(50); // Small debounce
33+
return true;
4034
}
41-
42-
if (select > 4) select = 0;
43-
return change;
35+
return false;
4436
}
4537

46-
47-
48-
void clearStrip(){
49-
for (int i = 0; i < NUM_OF_LEDS; i++){
50-
strip.setPixelColor(i, 0, 0, 0);
38+
void clearStrip() {
39+
for (int k = 0; k < NUM_OF_LEDS; k++) {
40+
strip.setPixelColor(k, 0, 0, 0);
5141
}
5242
strip.show();
5343
}
5444

55-
void greenChaserTask(int i){
45+
void greenChaserTask(int i) {
5646
int chaser_len = 5;
57-
5847
strip.setPixelColor(i, 0, 125, 0);
59-
60-
if (i < chaser_len) {
61-
62-
strip.setPixelColor((i-chaser_len+56)%56, 0, 0, 0);
63-
64-
}
65-
66-
strip.setPixelColor(i-chaser_len, 0, 0, 0);
67-
strip.setBrightness(140);
48+
// Modulo prevents negative index crashes
49+
strip.setPixelColor((i - chaser_len + NUM_OF_LEDS) % NUM_OF_LEDS, 0, 0, 0);
6850
strip.show();
6951
}
7052

71-
void randomLightsTask(int i){
72-
if (i == 0){
53+
void randomLightsTask(int i) {
54+
if (i == 0) {
7355
for (int r = 0; r < 56; r++) {
74-
red[r] = random(255);
75-
}
76-
77-
for (int g = 0; g < 56; g++) {
78-
green[g] = random(255);
79-
}
80-
81-
for (int b = 0; b < 56; b++) {
82-
blue[b] = random(255);
56+
red[r] = random(255);
57+
green[r] = random(255);
58+
blue[r] = random(255);
8359
}
8460
}
85-
8661
strip.setPixelColor(i, red[i], green[i], blue[i]);
87-
88-
for (int r = 0; r < 56; r++) {
89-
red[r] -= 4;
90-
}
91-
92-
for (int g = 0; g < 56; g++) {
93-
green[g] -= 4;
94-
}
95-
96-
for (int b = 0; b < 56; b++) {
97-
blue[b] -= 4;
62+
for (int k = 0; k < 56; k++) {
63+
if(red[k] > 4) red[k] -= 4;
64+
if(green[k] > 4) green[k] -= 4;
65+
if(blue[k] > 4) blue[k] -= 4;
9866
}
99-
100-
strip.setBrightness(140);
10167
strip.show();
10268
}
10369

104-
void colorBandTask(int i, int r, int g, int b){
105-
strip.setPixelColor(i, r, g, b);
106-
strip.setBrightness(140);
107-
strip.show();
108-
}
109-
110-
void greenBandTask(int i){
111-
colorBandTask(i, 0, 255, 0);
112-
}
113-
114-
void redBandTask(int i){
115-
colorBandTask(i, 255, 0, 0);
116-
}
117-
118-
void blueBandTask(int i){
119-
colorBandTask(i, 0, 0, 255);
70+
void colorBandTask(int i, int r, int g, int b) {
71+
strip.setPixelColor(i, r, g, b);
72+
strip.show();
12073
}
12174

122-
12375
void loop() {
124-
// put your main code here, to run repeatedly:
125-
126-
/* Read Sensor
127-
Sensor value will be 1023 when open,
128-
will drop to 78 when blocked
129-
When sensor is blocked, advance slection by 1*/
130-
131-
/* ALL GREEN */
76+
for (int i = 0; i < NUM_OF_LEDS; i++) {
77+
78+
// 1. Check for the press (and hold here)
79+
if (check()) {
80+
clearStrip();
81+
break; // Exit 'for' loop to start next animation
82+
}
13283

133-
for (i = 0; i < NUM_OF_LEDS; i ++){
84+
// 2. Run animations ONLY if sensor isn't being held
13485
if (select == 0) greenChaserTask(i);
13586
else if (select == 1) randomLightsTask(i);
136-
else if (select == 2) greenBandTask(i);
137-
else if (select == 3) blueBandTask(i);
138-
else if (select == 4) redBandTask(i);
139-
if (check()) {clearStrip(); break;}
87+
else if (select == 2) colorBandTask(i, 0, 255, 0); // Green
88+
else if (select == 3) colorBandTask(i, 0, 0, 255); // Blue
89+
else if (select == 4) colorBandTask(i, 255, 0, 0); // Red
90+
14091
delay(18);
141-
}
142-
14392
}
144-
145-
146-
147-
148-
149-
150-
151-
152-
int cigarettes = 0;
93+
}

0 commit comments

Comments
 (0)