-
Notifications
You must be signed in to change notification settings - Fork 0
/
Master.ino
53 lines (48 loc) · 1.05 KB
/
Master.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
int buzzerPin = 13;
int buttonPin = 9;
int state = '0';
int buttonState = 0;
int lastState = '0';
int lastButtonState = 0;
void setup() {
pinMode(buzzerPin, OUTPUT);
pinMode(buttonPin, INPUT);
noTone(buzzerPin);
Serial.begin(38400);
}
void loop() {
if (Serial.available() > 0) {
state = Serial.read();
delay(100);
Serial.println(state);
}
if (state != lastState)
{
if (state == '1') {
tone(buzzerPin, 5000);
delay(500);
noTone(buzzerPin);
//state == '0';
}
else if (state == '0') {
noTone(buzzerPin);
// state == 0;
}
}
lastState = state;
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
// digitalWrite(ledPin, HIGH);
Serial.write('1');
Serial.println('1');
delay(50);
Serial.write('0');
} else {
// digitalWrite(ledPin, LOW);
Serial.write('0');
}
delay(50);
}
lastButtonState = buttonState;
}