Skip to content

Instantly share code, notes, and snippets.

@shiffman
Created October 2, 2015 02:20
Show Gist options
  • Save shiffman/b9e7a50ea4ab39a1e710 to your computer and use it in GitHub Desktop.
Save shiffman/b9e7a50ea4ab39a1e710 to your computer and use it in GitHub Desktop.
Serial Examples for Synthesis Day
void setup() {
Serial.begin(9600);
pinMode(3,INPUT);
}
void loop() {
Serial.println(digitalRead(3));
delay(10);
}
// 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