I am receiving data from an LDR which I am inputting into processing. The data seems to be received to Arduino correctly however when I try to constrain and mapI have looked at the values into data processing can computebeing sent via the serial monitor and it prints a series of values with lettersall seems correct. However, the data that is being received in front rather than values betweenprocessing doesn't reflect the rangedata received by the LDR so I think I have specifieddone 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!
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); //constrain the
value lightval=map(rval,minval,maxval,0,255); between
0 and//Serial.println(lightval);
950 Serial.write(lightval);
}
PROCESSING CODE
import processing.serial.*;
Splash paintsplash;
Serial port;
float lightval=mapvalue=0;
void setup(rval,minval)
{
size(600,maxval600);
smooth();
background(255);
paintsplash= new Splash();
port=new Serial(this,0 Serial.list()[6],2559600);
//convertsprintArray(Serial.list());
}
void thedraw()
{
range ofpaintsplash.display();
rval paintsplash.splash();
Mapped fromdelay(200);
0-950 to
0-255 if(0<port.available())
now stored{
as lightval value=port.read();
Serial.}
println(lightvalvalue);
Serial.write
if(lightvalvalue<=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();
}
}
