-
-
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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