Created
March 23, 2014 12:34
-
-
Save pral2a/9722508 to your computer and use it in GitHub Desktop.
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; // The serial port | |
float valorArduinoA = 0; | |
float valorArduinoB = 0; | |
String valoresArduino[]; | |
long prevTimeColorChanges = 0; | |
boolean isRed = true; | |
void setup () { | |
size(800, 300); | |
smooth(); | |
noStroke(); | |
background(255); | |
serialSetup(); | |
} | |
void draw () { | |
background(255); | |
long currenTime = millis(); | |
if (valorArduinoB > 20 && (currenTime - prevTimeColorChanges) > 1000) { | |
if (isRed) { | |
isRed = false; | |
fill(0, 0, 255); | |
} | |
else { | |
isRed = true; | |
fill(255, 0, 0); | |
} | |
} | |
float diameter = map(valorArduinoA, 840, 940, height/2, height-10); | |
ellipse(width/2, height/2, diameter, diameter); | |
} | |
void serialSetup() { | |
println(Serial.list()); | |
myPort = new Serial(this, Serial.list()[5], 9600); | |
myPort.bufferUntil('\n'); | |
} | |
void serialEvent (Serial myPort) { | |
String lineaArduino = myPort.readStringUntil('\n'); | |
if (lineaArduino != null) { | |
lineaArduino = trim(lineaArduino); | |
valoresArduino = split(lineaArduino, ","); | |
valorArduinoA = float(valoresArduino[0]); | |
valorArduinoB = float(valoresArduino[1]); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
More processing Arduino examples: https://github.com/fablabbcn/Workshops/tree/master/Talking%20with%20processing