I am receiving data from an LDR which I am inputting into processing. The data seems to be received to Arduino correctly and I have looked at the data being sent via the serial monitor and it all seems correct. However, the data that is being received in processing doesn't reflect the data received by the LDR so I think I have done something wrong here but not sure what as I am fairly new to this all. (Please see image for what is printing in the processing serial monitor).
Any help identifying where I have gone wrong would be so so helpful!
ARDUINO CODE
int rval=0;
int lightval;
//Recorded minimum and maximum values
int minval=0;
int maxval=950;
void setup()
{
Serial.begin(9600);
}
void loop()
{
rval = analogRead(1);
//Serial.println(rval);
rval=constrain(rval,minval,maxval);
lightval=map(rval,minval,maxval,0,255);
//Serial.println(lightval);
Serial.write(lightval);
}
PROCESSING CODE
import processing.serial.*;
Splash paintsplash;
Serial port;
float value=0;
void setup()
{
size(600,600);
smooth();
background(255);
paintsplash= new Splash();
port=new Serial(this, Serial.list()[6],9600);
//printArray(Serial.list());
}
void draw()
{
paintsplash.display();
paintsplash.splash();
delay(200);
if(0<port.available())
{
value=port.read();
}
println(value);
if(value<=75)
{
fill(255,137,132);
}
else if(value>75 && value<=125)
{
fill(32,78,95);
}
else
{
fill(183,215,216);
}
}
PROCESSING CLASS - PAINT_SPLASH
class Splash
{
float x;
float y;
float size;
Splash()
{
x=0;
y=0;
size=int(random(35));
}
void display()
{
//fill(255,137,132);
noStroke();
ellipse(x,y,size,size);
}
void splash()
{
float xcord=int(random(600));
float ycord=int(random(600));
pushMatrix();
translate(xcord,ycord);
for ( float i =3; i < 29; i ++)
{
float splashX = x + random(100);
float splashY = y + random(100);
ellipse(splashX,splashY,size-i,(size-i+random(3)));
}
popMatrix();
}
}
Serial.println(lightval);
in the version whose output we see.