-
Notifications
You must be signed in to change notification settings - Fork 0
/
switchcount.ino
59 lines (56 loc) · 1.02 KB
/
switchcount.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
54
55
56
57
58
59
#include<stdio.h>
int red=D0;
int green=D1;
int blue=D2;
int SW=D3;
int val;
int count=0;
void setup()
{
pinMode(SW,INPUT_PULLUP);
pinMode(red,OUTPUT);
pinMode(blue,OUTPUT);
pinMode(green,OUTPUT);
Serial.begin(9600);
digitalWrite(red,1);
digitalWrite(green,1);
digitalWrite(blue,1);
// // put your setup code here, to run once:
}
void loop() {
val=digitalRead(SW);
if(val==0)
{
count=count+1;
Serial.print(count);
if(count==1)
{
digitalWrite(red,0);
digitalWrite(blue,1);
digitalWrite(green,1);
Serial.print("red");
}
else if(count==2)
{
digitalWrite(red,1);
digitalWrite(blue,1);
digitalWrite(green,0);
Serial.print("green");
}
else if(count==3)
{
digitalWrite(red,1);
digitalWrite(blue,0);
digitalWrite(green,1);
Serial.print("blue");
}
else
{
digitalWrite(red,1);
digitalWrite(blue,1);
digitalWrite(green,1);
count=0;
}
}
delay(250);
}