Skip to content

Instantly share code, notes, and snippets.

@pral2a
Created March 23, 2014 12:34
Show Gist options
  • Save pral2a/9722508 to your computer and use it in GitHub Desktop.
Save pral2a/9722508 to your computer and use it in GitHub Desktop.
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]);
}
}
@pral2a
Copy link
Author

pral2a commented Mar 23, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment