Skip to content

Commit 55427b2

Browse files
committed
updates
1 parent dc4c10d commit 55427b2

4 files changed

Lines changed: 5939 additions & 0 deletions

File tree

6-channel-LED/6-channel-LED.ino

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
int ledPins[] = {2, 3, 9, 10, 11, 12};
2+
int intensity = 127;
3+
int difference = 10;
4+
long lastLoopTime = 0;
5+
int interval = 50;
6+
int thisLed = 0;
7+
8+
void setup() {
9+
for (int p = 0; p < 6; p++) {
10+
pinMode(ledPins[p], OUTPUT);
11+
}
12+
Serial.begin(9600);
13+
}
14+
15+
void loop() {
16+
if (millis() - lastLoopTime > interval) {
17+
// increment thisLed
18+
thisLed++;
19+
thisLed %= 6;
20+
21+
// increment intensity:
22+
// intensity += difference;
23+
24+
// for a more random effect,
25+
// comment out the previous line and add these lines:
26+
//reset the random number generator when on the first LED:
27+
if (thisLed == 0) randomSeed(millis());
28+
//increment with a random number:
29+
intensity += random(-difference, difference);
30+
31+
// if intensity gets to an extreme, reverse difference:
32+
if (intensity <= 0 || intensity >= 255) {
33+
difference = -difference;
34+
}
35+
36+
37+
// constrain intensity:
38+
intensity = constrain(intensity, 0, 255);
39+
// set LED intensity:
40+
analogWrite(ledPins[thisLed], intensity);
41+
// update timestamp:
42+
lastLoopTime = millis();
43+
}
44+
}

0 commit comments

Comments
 (0)