kee123
January 11, 2023, 6:04am
1
Hello everyone!. Its been a time where I have been developing a heatmap code and somehow I made my code to an extent where I collect data from my sensor and read the analog values in the heat map grid. I have made a 6*4 heatmap grid where the colors are not getting reflected. I don't know which code of line is missing the color grid is not reflecting colors with new text values when runs in an array. Plz help me with this if u know.
Here's the code:
import processing.serial.*;
int box_size = 50;
Serial mySerial;
int val;
String myString = null;
int nl = 10;
int myVal;
float a[][]={{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0},{0, 0, 0, 0},{0, 0, 0, 0}};
float Values=0;
String delim = "v1m";
String list[];
int x=0;
int y=0;
int Z=0;
void setup()
{
size(800, 800);
colorMode(HSB, 360, 100, 100);
background(100);
String portName = "COM34";
mySerial = new Serial(this, portName, 9600);
printArray(Serial.list());
}
void draw()
{
fill(50);
stroke(100);
strokeWeight(2);
while (mySerial.available()>0)
{
myString = mySerial.readStringUntil('\n');
//println(remove(myString,"Nan"));
if(myString!=null)
{
list=split(myString.trim(),",");
if(++Z>5)
{
Z=0;
}
a[x][y] = myVal; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
println(y,x);
//println(a[x][y]);
fill(a[x][y],100,100);
rect( x * box_size, y* box_size, box_size, box_size);
if (++x >= 6)
{
if (++y >= 4) y= 0;
x=0;
}
}
delay(0);
}
}
Here's the output:
Posting the output of this would be handy...
I don't see any attempt to convert the strings in list
to numbers.
kee123
January 11, 2023, 7:23am
5
No, I didn't display those values...there's a code where it can show values and I checked the values it has been displaying properly.
kee123
January 11, 2023, 7:25am
6
this is my ignored lines of code:
import processing.serial.*;
int box_size = 50;
Serial mySerial;
int val;
String myString = null;
int nl = 10;
int myVal;
float a[][]={{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0},{0, 0, 0, 0},{0, 0, 0, 0}};
float Values=0;
String delim = "v1m";
String list[];
int x=0;
int y=0;
int Z=0;
void setup()
{
size(800, 800);
colorMode(HSB, 360, 100, 100);
background(100);
String portName = "COM34";
mySerial = new Serial(this, portName, 9600);
printArray(Serial.list());
}
void draw()
{
fill(50);
stroke(100);
strokeWeight(2);
while (mySerial.available()>0)
{
myString = mySerial.readStringUntil('\n');
//println(remove(myString,"Nan"));
if(myString!=null)
{
//println(trim(myString));
//{String cf=trim(myString);
// println(split(cf,","));
//background(0);
//println(split(myString.trim(),","));
list=split(myString.trim(),",");
int Z=0;
if(++Z>5)
{
Z=0;
}
//println(myVal);
//println(Integer.valueOf(myString.trim()));
//for(x=0;x<6;x++)
//{
// myVal = int(Values);
// print(myVal);
//}
//myVal=int(myString);
//println(myVal);
//for(x=0; x<4; x++)
// {
// for(y=0; y<4; y++)
// {
//
a[x][y] = myVal; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
println(y,x);
//println(a[x][y]);
fill(a[x][y],100,100);
rect( x * box_size, y* box_size, box_size, box_size);
if (++x >= 6)
{
if (++y >= 4) y= 0;
x=0;
}
//}
// }
}
delay(0);
}
}
//int readval()
//{
// int value =0;
// if ( mySerial.available() > 0)
// {
// value = mySerial.read();
// }
// return value;
//}
6v6gt
January 11, 2023, 10:24am
7
This appears to be a continuation of Error in the heatmap code
I guess you have to use a nested for loop if you want to fill an array.
Something like this:
// assuming array shape a[6][4]
for ( y = 0 ; y < 6 ; y++ ) {
for ( x = 0 ; x < 4 ; x++ ) {
a[ y ][ x ] = < your new value >
// fill cell etc.
}
}
I suggest you try hard coding some numbers into your processing code just to get the array and colours right.
After that, start trying to integrate it with the data stream you are getting from the Arduino.
kee123
January 11, 2023, 10:31am
8
but I didn't use this line i disabled this line in my code.
kee123
January 11, 2023, 10:32am
9
I guess the values are getting filled in an array. That's how the colors are reflected. Can u get me what I say?
system
Closed
July 10, 2023, 10:33am
10
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.