Created
August 5, 2016 09:44
-
-
Save dybber/500e09716fcf8b09880f0729682dead1 to your computer and use it in GitHub Desktop.
Arduino/Processing SerialTest
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
int colour = 0; | |
void setup() { | |
Serial.begin(9600); | |
} | |
void loop() { | |
colour = (colour + 1) % 255; | |
Serial.println(colour); | |
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
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