Skip to content

Instantly share code, notes, and snippets.

@dropmeaword
Forked from anonymous/gist:02d9511dda8c4a2a7227
Last active October 7, 2015 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dropmeaword/920dc8bca2bebeb6607f to your computer and use it in GitHub Desktop.
Save dropmeaword/920dc8bca2bebeb6607f to your computer and use it in GitHub Desktop.
IDArnhem: This code must be loaded in the Arduino and it runs the buzzer.
/**
* This little program runs in the Arduino, one that is plugged
* to a computer with a USB cable. This cable will be our "serial"
* connection. In the computer we will run the P5 sketch that will
* tell the Arduino through "serial" when to do its thing.
*
* 1. Load this program into your Arduino.
* 2. Load the Processing sketch, change the "serial port" in the P5 code to point to the correct Arduino.
* 3. Run the processing sketch.
* 4. Buzzzzzz
*/
int DATA_RATE = 9600;
int buzzer = 8;
byte msg = 0;
void setup() {
Serial.begin(DATA_RATE);
delay(30); // wait to make sure serial is open and fine
pinMode(buzzer, OUTPUT);
}
void buzz() {
tone(buzzer, 1500); // play 400 Hz tone for 500 ms
delay(300);
noTone(buzzer);
}
void loop() {
// check if data has been sent from the computer to the arduino
if (Serial.available()) {
// if there's data waiting, read the most recent byte
msg = Serial.read();
// if we get a capital B from the computer, we buzz the buzzer
if(msg == 'B') {
buzz();
}
}
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment