Hi, Im very new to this. Im trying to show a constant serial communication form a lightsensor via Arduino as constantly shifting percentage numbers in processing. Problem is the percentage is pretty wild and never goes to 0% or 100% ( I belive 50% is the max it has gone to) So I would like to hear with you guys if my code is wrong! if not I guess the serial communication is messed up. Here is the processing code:
The light sensor goes from 0 to 255, I used the Arduino calibration example if anyone is familiar with it.
//import Serial communication library
import processing.serial.*;
//init variables
Serial commPort;
int lightread;
double divide;
float percent;
PFont font12;
PFont font24;
void setup()
{
//setup fonts for use throughout the application
font12 = loadFont("Arial-Black-24.vlw");
font24 = loadFont("Arial-Black-48.vlw");
//set the size of the window
size(250, 200);
//init serial communication port
commPort = new Serial(this, Serial.list()[0], 9600);
}
void draw()
{
//get the ligtsensor value from the serial port
while (commPort.available() > 0)
{
lightread = commPort.read();
divide = lightread / 2.55;
percent = ((float)divide) ; // divide 255 by 2,5 to get the percentage