// communication with an arduino pro mini // on a bread board via the HC-05 bluetooth chip #define NOTE_AS1 58 #define NOTE_B1 62 #define NOTE_C2 65 #define NOTE_CS2 69 #define NOTE_D2 73 #define NOTE_DS2 78 #define NOTE_E2 82 #define NOTE_F2 87 #define NOTE_FS2 93 #define NOTE_G2 98 #define NOTE_GS2 104 #define NOTE_A2 110 #define NOTE_AS2 117 #define NOTE_B2 123 #define NOTE_C3 131 #define NOTE_CS3 139 #define NOTE_D3 147 #define NOTE_DS3 156 #define NOTE_E3 165 #define NOTE_F3 175 #define NOTE_FS3 185 #define NOTE_G3 196 #define NOTE_GS3 208 #define NOTE_A3 220 #define NOTE_AS3 233 #define NOTE_B3 247 #define NOTE_C4 262 #define NOTE_CS4 277 #define NOTE_D4 294 #define NOTE_DS4 311 #define NOTE_E4 330 #define NOTE_F4 349 #define NOTE_FS4 370 #define NOTE_G4 392 #define NOTE_GS4 415 #define NOTE_A4 440 int data = 0; int led = 13; // onboard led for testing int piezo = 10; // piezo speaker output pin int length = 400; // length of notes int pitch = 440; // middle A void setup() { pinMode(led, OUTPUT); pinMode(piezo, OUTPUT); Serial.begin(9600); // ... while (!Serial) { // wait for serial port to connect. // Needed for native USB port only ; } Serial.println("Blueboard: printing serial data..."); } void loop() { if (Serial.available() > 0) { data = Serial.read(); Serial.println(""); //Serial.print("rx:"); Serial.print('"'); Serial.write(data); Serial.print('"'); Serial.println(" ascii"); Serial.print(data); Serial.println(" decimal"); Serial.print(data, HEX); Serial.println(" hex"); } if (data == 's') { Serial.println("Siren!"); tone(piezo, pitch, length); delay(length+60); tone(piezo, pitch+15, length); delay(length+60); tone(piezo, pitch+30, 200); delay(260); } else if (data == 'l') { Serial.println("Increase note length by 50 ms"); length = length+50; } else if (data == 'L') { Serial.println("Decrease note length by 50 ms"); length = length-50; } else if (data == 'p') { Serial.println("Increase pitch by 15 herz"); pitch = pitch+15; } else if (data == 'P') { Serial.println("Decrease pitch by 15 herz"); pitch = pitch-15; } else if (data == 'i') { Serial.print("Pitch (Herz):"); Serial.println(pitch, DEC); Serial.print("Note Length (milliseconds):"); Serial.println(length, DEC); } else if (data == 'S') { // silence } else if (data == 'a') { Serial.println("Alarm!"); for (int ii = 0; ii < 5; ii++) { tone(piezo, pitch, length); delay(length+60); tone(piezo, pitch-30, length); delay(length+60); } } else if (data == 'b') { // blink on board led Serial.println("Blink!"); for (int ii = 0; ii < 5; ii++) { digitalWrite(led, HIGH); delay(100); digitalWrite(led, LOW); delay(100); } } else {} }