Created
October 2, 2015 02:20
-
-
Save shiffman/b9e7a50ea4ab39a1e710 to your computer and use it in GitHub Desktop.
Serial Examples for Synthesis Day
This file contains 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
void setup() { | |
Serial.begin(9600); | |
pinMode(3,INPUT); | |
} | |
void loop() { | |
Serial.println(digitalRead(3)); | |
delay(10); | |
} |
This file contains 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
// the serial object | |
var serial; | |
// the data | |
var x = 0; | |
function setup() { | |
createCanvas(600, 400); | |
// Make the object | |
serial = new p5.SerialPort(); | |
var ports = serial.list(); | |
// It's often the last port | |
var portName = ports[ports.length-1]; | |
// Or you might just know it | |
// var portName= "/dev/cu.usbmodemfd1231"; | |
serial.open(portName); | |
// Register a function that will handle the serial data | |
serial.onData(gotData); | |
} | |
function gotData(){ | |
// Put the data in the x variable | |
x = serial.readString(); | |
} | |
function draw() { | |
background(255) | |
ellipse(x, 50, 20, 20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment