-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleSiren.ino
63 lines (49 loc) · 1.75 KB
/
SimpleSiren.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
// Simple Siren by V205.
// Thank you to Arduino.
/*
The circuit is a piezo connectedto digital pin 7 and ground.
________________
|Piezo| Arduino|
| + | D7 |
| - | GND |
*/
// constants won't change. Used here to set a pin number:
const int piezoPin = 7; // the number of the piezo pin
// Try playing around with these constants.
const int updateInterval = 10; //The interval that the siren's pitch is updated at in milliseconds(there are 1000 milliseconds in a second)
const int pitchHighBoundary = 700;//the siren will go to this pitch then go back again.
const int pitchLowBoundary = 600;// the siren will go to this pitvh then the pitch will go up again.
const int pitchChange = 10;//This is the amount that the pitch changes with everytime the pitch is updated.
void setup() {
// Set piezo Pin to output.
pinMode(piezoPin, OUTPUT);
//Begin Serial comms.
Serial.begin(9600);
delay(1000);
Serial.println("Simple Siren by V205.");
Serial.print("piezoPin = " );
Serial.println(piezoPin);
Serial.print("updateInterval = ");
Serial.println(updateInterval);
Serial.print("pitchHighBoundary = ");
Serial.println(pitchHighBoundary);
Serial.print("pitchLowBoundary = ");
Serial.println(pitchLowBoundary);
Serial.print("pitchChange = ");
Serial.println(pitchChange);
}
void loop() {
// put your main code here, to run repeatedly:
for (int pitch = pitchLowBoundary; pitch <= pitchHighBoundary; pitch+=pitchChange) {
tone(piezoPin,pitch);
Serial.print("pitch = ");
Serial.println(pitch);
delay(updateInterval);
}
for (int pitch = pitchHighBoundary; pitch >= pitchLowBoundary; pitch-=pitchChange) {
tone(piezoPin,pitch);
Serial.print("pitch = ");
Serial.println(pitch);
delay(updateInterval);
}
}