-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoice_control.ino
105 lines (69 loc) · 2.02 KB
/
Voice_control.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
String voice;
const int led1 = 2;
const int led2 = 3;
const int led3 = 4;
const int led4 = 5;
const int led5 = 6;
const int led7 = 8;
void setup()
{
Serial.begin(9600);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led7, OUTPUT);
digitalWrite(led7,HIGH);
}
void loop()
{
while (Serial.available())
{
delay(10);
char c = Serial.read();
if (c == '#') {break;}
voice += c;
}
if (voice.length() > 0)
{
Serial.println(voice);
if(voice == "*all on")
{
allon();
}
else if(voice == "*all of")
{
alloff();
}
else if(voice == "*TV on"){digitalWrite(led1, HIGH);}
else if(voice == "*relay on") {digitalWrite(led7,LOW);}
else if(voice == "*fan on") {digitalWrite(led2, HIGH);}
else if(voice == "*computer on") {digitalWrite(led3, HIGH);}
else if(voice == "*bedroom lights on") {digitalWrite(led4, HIGH);}
else if(voice == "*bathroom lights on") {digitalWrite(led5, HIGH);}
else if(voice == "*TV off") {digitalWrite(led1, LOW);}
else if(voice == "*relay of") {digitalWrite(led7, HIGH);}
else if(voice == "*fan of") {digitalWrite(led2, LOW);}
else if(voice == "*computer of") {digitalWrite(led3, LOW);}
else if(voice == "*bedroom lights of") {digitalWrite(led4, LOW);}
else if(voice == "*bathroom lights of") {digitalWrite(led5, LOW);}
voice="";
}
}
void allon()
{
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
}
void alloff()
{
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
}