-
Notifications
You must be signed in to change notification settings - Fork 3
/
smartlock_unor3.ino
60 lines (57 loc) · 1003 Bytes
/
smartlock_unor3.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
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //RX=2,TX=3 ESP8266
int beep = 4;
void setup() {
pinMode(beep, OUTPUT); //蜂鸣器
digitalWrite(beep, LOW);
Serial.begin(9600);
Serial.print("Welcome to use!\n");
while (!Serial) {
;
}
mySerial.begin(9600);
delay(1000);
Serial.println("Start");
openBeep(3);
}
void openBeep(int times)
{
for (int i = 0; i < times; i++)
{
digitalWrite(beep, LOW);
delay(100);
digitalWrite(beep, HIGH);
delay(100);
}
}
void loop() {
if (mySerial.available())
{
String comdata = "";
int i = 0;
while (mySerial.available() > 0)
{
i++;
char a = char(mySerial.read());
comdata += a;
delay(2);
}
Serial.println(comdata);
if (comdata == "a" )
{
openBeep(1);
}
else if (comdata == "b" )
{
openBeep(2);
}
else if (comdata == "c" )
{
openBeep(3);
}
else if (comdata == "d" )
{
openBeep(4);
}
}
}