/
W8_RGBled.ino
53 lines (46 loc) · 1.04 KB
/
W8_RGBled.ino
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
45
46
47
48
49
50
51
52
53
// Description: This program is designed to blink each color of a RGB LED
// When the reading on the input pin is low. You can switch the delay to your
// convienience :)
#define red 6
#define blue 7
#define green 8
//Pin outputs for RGB LED
#define input 2
//Input pin for buttom
void setup()
{
pinMode(red,OUTPUT);
pinMode(blue,OUTPUT);
pinMode(green,OUTPUT);
pinMode(input,INPUT);
return;
}
long unsigned delayCurrent=0, delayPrev=0;
const int Delay=100;
int count=0;
void loop()
{
delayCurrent=millis();
if( (delayCurrent-delayPrev>Delay) && digitalRead(input)==LOW )
{
if(count==0 || count==1 || count==2)
digitalWrite(red,HIGH);
else
digitalWrite(red,LOW);
//RED if
if( count==1 || count==2 || count==3 || count==5)
digitalWrite(green,HIGH);
else
digitalWrite(green,LOW);
//GREEN if
if(count==2 || count==3 || count==4)
digitalWrite(blue,HIGH);
else
digitalWrite(blue,LOW);
//BLUE if
count++;
if(count>5)
count=0;
delayPrev=delayCurrent;
}
}