-
Notifications
You must be signed in to change notification settings - Fork 0
/
Serial_Print.ino
106 lines (91 loc) · 2.02 KB
/
Serial_Print.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
int ledRed=5, ledGreen=6, ledWhite=7;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
pinMode(ledWhite, OUTPUT);
Serial.println("Welcome to the Arduino Workshop");
Serial.println("\n Enter Choice \n 1-Red \n 2-Green \n 3-White \n 4-Turn On All Lights \n 5-Turn Off All Lights");
}
int choice;
bool on1=0,on2=0,on3=0;
void loop()
{
if(Serial.available())
{
choice=Serial.parseInt();
Serial.println("\n You had Selected \t");
if(choice==1)
{
Serial.print("Red");
}
if(choice==2)
{
Serial.print("Green");
}
if(choice==3)
{
Serial.print("White");
}
if(choice==4)
{
Serial.print("Turn On all the lights");
}
if(choice==5)
{
Serial.print("Turn Off All the Lights");
}
switch(choice){
case 1:
on1=!on1;
if(on1)
{
digitalWrite(ledRed, HIGH);
}
else
{
digitalWrite(ledRed, LOW);
}
break;
case 2:
on2=!on2;
if(on2)
{
digitalWrite(ledGreen, HIGH);
}
else
{
digitalWrite(ledGreen, LOW);
}
break;
case 3:
on3=!on3;
if(on3)
{
digitalWrite(ledWhite, HIGH);
}
else
{
digitalWrite(ledWhite, LOW);
}
break;
case 4:
on1=!on1;
on2=!on2;
on3=!on3;
if(on1,on2,on3)
{
digitalWrite(ledRed, HIGH);
digitalWrite(ledGreen, HIGH);
digitalWrite(ledWhite, HIGH);
}
break;
case 5:
digitalWrite(ledRed, LOW);
digitalWrite(ledGreen, LOW);
digitalWrite(ledWhite, LOW);
break;
}
}
}