Arduino sensor update in processing

edited September 2015 in Arduino

**Hey all, I am using Arduino and Processing. On my Arduino I am simply using the Standard Firmata. My goal is for the sensor data of Arduino to be written out in Processing in a readable way. my first code was: This sort of "cheats" with the white rectangle over the text every-time to update to the new information. **

import processing.serial.*; import cc.arduino.*;

Arduino arduino; int sensorpin = 0; // analog pin used to connect the sharp sensor int val = 0; // variable to store the values from sensor(initially zero)

void setup() { //println(Arduino.list()); arduino = new Arduino(this, Arduino.list()[0], 57600); background(255); size(1000, 1000); }

void draw() { val=arduino.analogRead(sensorpin); // reads the value of the sharp sensor stroke (255); fill(255); rect(0, 0, 400, 400);

if (val >= 0) { textSize(32); fill(0, 102, 153, 204); text("sensor pin value is ", 10, 30);
text(val, 10, 60); println (val); } delay(300);

}

**** My second goals is for when there is a mouseclicked, I want the data to change color but to still update. This is where I am having trouble. The Sensor data changes to the current value in the new color when clicked but not in between (when not clicked) ... any ideas?**** import processing.serial.*; import cc.arduino.*;

Arduino arduino; int sensorpin = 0; // analog pin used to connect the sharp sensor int val = 0; // variable to store the values from sensor(initially zero) int DayNight = 0; void setup() { //println(Arduino.list()); arduino = new Arduino(this, Arduino.list()[0], 57600); background(255); size(1800, 800); }

void draw() {
val=arduino.analogRead(sensorpin); // reads the value of the sharp sensor

}

void mouseClicked() { if (DayNight == 0) { val=arduino.analogRead(sensorpin);
stroke (255); fill(255); rect(0, 0, 400, 400);

fill(0, 102, 153, 204);
textSize(32);
text("sensor pin value is ", 10, 30);  
text(val, 10, 60);
println (val);

DayNight = 1;

} else { val=arduino.analogRead(sensorpin);
stroke (255); fill(255); rect(0, 0, 400, 400);

fill(0, 102, 13, 104); 
textSize(32);
text("sensor pin value is ", 10, 30);  
text(val, 10, 60);
println (val);
DayNight = 0;

} }

Tagged:

Answers

Sign In or Register to comment.