Skip to content

Instantly share code, notes, and snippets.

@dybber
Created August 5, 2016 09:44
Show Gist options
  • Save dybber/500e09716fcf8b09880f0729682dead1 to your computer and use it in GitHub Desktop.
Save dybber/500e09716fcf8b09880f0729682dead1 to your computer and use it in GitHub Desktop.
Arduino/Processing SerialTest
int colour = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
colour = (colour + 1) % 255;
Serial.println(colour);
delay(10);
}
import processing.serial.*;
Serial myPort;
String sensorReading="";
int colour = 0;
void setup(){
size(600,600);
myPort = new Serial(this, "/dev/ttyACM0", 9600);
myPort.bufferUntil('\n');
}
void draw(){
background(colour, colour, colour);
}
void serialEvent (Serial myPort){
sensorReading = myPort.readStringUntil('\n');
if (sensorReading != null){
sensorReading=trim(sensorReading);
colour = Integer.parseInt(sensorReading);
println(colour);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment