-
Notifications
You must be signed in to change notification settings - Fork 0
/
buzzer.ino
44 lines (40 loc) · 954 Bytes
/
buzzer.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
const int buzzer = 8;
const int outputA = 6;
const int outputB = 7;
int counter = 0;
int aState;
int aLastState;
int makeNoise = 0;
void setup(){
pinMode(buzzer, OUTPUT);
pinMode (outputA,INPUT);
pinMode (outputB,INPUT);
aLastState = digitalRead(outputA);
Serial.begin(9600);
Serial.setTimeout(0.5);
}
void loop(){
if (Serial.available()) {
makeNoise = Serial.readString().toInt();
// Serial.println(makeNoise);
if (makeNoise == 0 || counter == 0) {
noTone(buzzer);
}
else {
tone(buzzer, counter * 200);
// Serial.print("set buzzer to ");
// Serial.println(counter * 200);
}
}
aState = digitalRead(outputA);
if (aState != aLastState) {
if (digitalRead(outputB) != aState) {
if (counter > 0) { counter--; }
} else {
if (counter < 20) { counter++; }
}
// Serial.print("Position: ");
// Serial.println(counter);
}
aLastState = aState;
}