Last active
October 7, 2015 15:36
-
-
Save dropmeaword/d913cd0fcd6f4e515b0a to your computer and use it in GitHub Desktop.
IDArnhem: This code runs in Processing from your laptop and communicates with the Arduino using the serial protocol.
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
| import processing.serial.*; | |
| int DATA_RATE = 9600; // must be the same as the datarate that the Arduino is using | |
| Serial serial; | |
| void setup() | |
| { | |
| size(200, 200); | |
| // the ard variable must be = to the location of your Arduino | |
| // say: /dev/tty.usbmodem1442 | |
| // or something like that. | |
| String ard = Serial.list()[0]; // try to autodetect Arduino, if it fails, just hardcode the port | |
| serial = new Serial(this, ard, DATA_RATE); | |
| } | |
| void sendBuzzCommand() { | |
| println("Telling the buzzer to buzzzzz"); | |
| // send the command 'B' to the Arduino | |
| serial.write('B'); | |
| // when we send a capital 'B' through serial from our computer, it will go | |
| // to the Arduino which is programmed to react to that letter by buzzing the buzzer. | |
| } | |
| void draw() { | |
| background(255, 200, 200); // I like salmon-pink | |
| text("Press 'b' to buzz", 8, 18); | |
| } | |
| void keyPressed() { | |
| switch(key) { | |
| case 'B': | |
| case 'b': | |
| sendBuzzCommand(); | |
| break; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment