Hello!..i have been a developing a code where I'm reading the analog values from the sensor and reading the analog values in the heat map matrix ( 4* 4) in processing IDE. I have read the values successfully from the Arduino and filled the analog values into the heat map but then I cannot read proper values into the matrix(processing IDE)..im getting 0 in the reading portal and the values are generated in between the 0's. how to overcome the error and print the analog values and fill the heat map matrix.??.
Here's my Arduino code:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}
Arduino result:
458
457
463
here's my processing IDE code:
import processing.serial.*;
int box_size = 50;
Serial mySerial;
int val;
String myString = null;
int nl = 10;
float myVal;
int a[][]={{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
void setup()
{
size(200,200);
colorMode(HSB,240,100,100);
background(100);
String portName = "COM29";
mySerial = new Serial(this, portName, 9600);
printArray(Serial.list());
}
void draw()
{
fill(50);
stroke(100);
strokeWeight(2);
while(mySerial.available()>0){
myString = mySerial.readStringUntil(nl);
if(myString!=null){
background(0);
myVal= float (myString);
myVal = myVal;
println(myVal);
for(int x=0; x<4; x++)
{
for(int y=0; y<4; y++)
{
//a[x][y]=readval();
println(a[x][y]);
fill(a[x][y],100,100);
rect( x * box_size, y * box_size, box_size, box_size);
}
}
}
delay(0);
}
}
//int readval()
//{
// int value =0;
// if ( mySerial.available() > 0)
// {
// value = mySerial.read();
// }
// return value;
//}
Processing IDE result :
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
493
0
0
0
0
0
0
how to read the values continuously without any 0's??.
I need this help badly.. Thank u.