/
Interactive_LED_Chase_Effect.txt
44 lines (44 loc) · 1.26 KB
/
Interactive_LED_Chase_Effect.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Courier New;}}
{\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\f0\fs20 // Create array for LED pins\par
byte ledPin[] = \{2, 3, 4, 5, 6, 7, 8, 9\};\par
int ledDelay; // delay between changes\par
int direction = 1;\par
int currentLED = 0;\par
unsigned long changeTime;\par
int potPin = 2; // select the input pin for the potentiometer\par
\par
void setup() \{\par
// set all pins to output\par
for (int x=0; x<10; x++) \{\par
pinMode(ledPin[x], OUTPUT); \}\par
changeTime = millis();\par
\}\par
void loop() \{\par
// read the value from the pot\par
ledDelay = analogRead(potPin);\par
// if it has been ledDelay ms since last change\par
\par
if ((millis() - changeTime) >\par
ledDelay) \{\par
changeLED();\par
changeTime = millis();\par
\}\par
\}\par
void changeLED() \{\par
// turn off all LED's\par
for (int x=0; x<10; x++) \{\par
digitalWrite(ledPin[x], LOW);\par
\}\par
// turn on the current LED\par
digitalWrite(ledPin[currentLED], HIGH);\par
\par
// increment by the direction value\par
currentLED += direction;\par
// change direction if we reach the end\par
\par
if (currentLED == 9) \{direction =\par
-1;\}\par
if (currentLED == 0) \{direction = 1;\}\par
\}\par
}