We are about to switch to a new forum software. Until then we have removed the registration on this forum.
**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;
} }
Answers
You'll get a better response if you format your code. Here's how:
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text