Cannot write to 2D int array
hi,
i have in beggining of code created 2d int array (it should global)
anywhere else, write values it
and in part of code, tried read it
but when print values
i 0;0;0;0;0.
so tried read values after writing them array
i output
uklad00000
10;14;255;0;0;1
-> saved values 10;14;255;0;0. if read them, thea 0;0;0;0;0
what's wrong?
complete code:
thanks.
(sorry english)
i have in beggining of code created 2d int array (it should global)
code: [select]
int vyrovnavacileds[15][5];
anywhere else, write values it
code: [select]
vyrovnavacileds[interval][0] == from;
vyrovnavacileds[interval][1] == to;
vyrovnavacileds[interval][2] == r;
vyrovnavacileds[interval][3] == g;
vyrovnavacileds[interval][4] == b;
and in part of code, tried read it
code: [select]
for(int = 0; < interval; i++)
{
= vyrovnavacileds[i][0];
= vyrovnavacileds[i][1];
value.r = vyrovnavacileds[i][2];
value.g = vyrovnavacileds[i][3];
value.b = vyrovnavacileds[i][4];
}
but when print values
code: [select]
serial1.print(from);
serial1.print(";");
serial1.print(to);
serial1.print(";");
serial1.print(value.r);
serial1.print(";");
serial1.print(value.g);
serial1.print(";");
serial1.println(value.b);
i 0;0;0;0;0.
so tried read values after writing them array
code: [select]
vyrovnavacileds[interval][0] == from;
vyrovnavacileds[interval][1] == to;
vyrovnavacileds[interval][2] == r;
vyrovnavacileds[interval][3] == g;
vyrovnavacileds[interval][4] == b;
serial1.print("uklad"); //prints values saved field
serial1.print(vyrovnavacileds[interval][0]);
serial1.print(vyrovnavacileds[interval][1]);
serial1.print(vyrovnavacileds[interval][2]);
serial1.print(vyrovnavacileds[interval][3]);
serial1.println(vyrovnavacileds[interval][4]);
//prints values, i'm saving array
serial1.print(from);
serial1.print(";");
serial1.print(to);
serial1.print(";");
serial1.print(r);
serial1.print(";");
serial1.print(g);
serial1.print(";");
serial1.print(b);
serial1.print(";");
serial1.println(interval);
i output
uklad00000
10;14;255;0;0;1
-> saved values 10;14;255;0;0. if read them, thea 0;0;0;0;0
what's wrong?
complete code:
code: [select]
//reads data serial port , lights led strip
#include <ws2812.h>
int striplen = 120;
ws2812 led(striplen);
crgb value;
int vstup;
int from;
int to;
int r;
int g;
int b;
int interval;
int check;
int reccheck;
boolean checkpass = false;
int vyrovnavacileds[15][5];
void setup()
{
led.setoutput(5);
serial.begin(9600);
serial.settimeout(5);
serial1.begin(9600);
value.r = 0;
value.g = 0;
value.b = 0;
for(int _ = 0; _ < striplen; _++)
{
led.set_crgb_at(_, value);
}
led.sync();
}
void loop()
{
if(serial.available())
{
cti();
if(vstup == 98)
{
serial1.println("vs");
serial1.println(string(vstup));
zpracuj();
}
else
{
}
}
}
void cti()
{
vstup = serial.read();
return;
char precteno[1];
int bytes;
bytes = serial1.readbytes(precteno, 1);
vstup = precteno[0];
}
void zpracuj()
{
cti();
if(vstup < 128) //neni zovrazvaci zprava
{
serial1.println("i");
serial1.println(vstup);
= int(vstup);
cti();
serial1.println("i");
serial1.println(vstup);
= vstup;
cti();
serial1.println("i");
serial1.println(vstup);
r = vstup;
cti();
serial1.println("i");
serial1.println(vstup);
g = vstup;
cti();
serial1.println("i");
serial1.println(vstup);
b = vstup;
if(interval < 15)
{
interval = 1; //to make sure, nothing wrong index
vyrovnavacileds[interval][0] == from;
vyrovnavacileds[interval][1] == to;
vyrovnavacileds[interval][2] == r;
vyrovnavacileds[interval][3] == g;
vyrovnavacileds[interval][4] == b;
serial1.print("uklad");
serial1.print(vyrovnavacileds[interval][0]);
serial1.print(vyrovnavacileds[interval][1]);
serial1.print(vyrovnavacileds[interval][2]);
serial1.print(vyrovnavacileds[interval][3]);
serial1.println(vyrovnavacileds[interval][4]);
value.r = r;
value.g = g;
value.b = b;
for(int led = from; led < +1; led++)
{
led.set_crgb_at(led, value);
}
serial1.print(from);
serial1.print(";");
serial1.print(to);
serial1.print(";");
serial1.print(r);
serial1.print(";");
serial1.print(g);
serial1.print(";");
serial1.print(b);
serial1.print(";");
serial1.println(interval);
interval++;
}
}
else if(vstup == 130) //konrolní součet
{
serial1.println("ks");
cti();
check = 0;
reccheck = vstup;
for(int = 0; < 15; a++)
{
for(int b = 0; b < 5; b++)
{
check += vyrovnavacileds[a][b];
}
}
check = check % 256;
serial1.println("checkcount ");
serial1.println(check);
reccheck = reccheck % 256;
serial1.println(reccheck);
}
else if(vstup > 130) //zobrazovani
{
serial1.println("zobr");
if(check = reccheck)
{
serial1.println("chok");
//kod pro zobrazeni
for(int = 0; < interval; i++)
{
= vyrovnavacileds[i][0];
= vyrovnavacileds[i][1];
value.r = vyrovnavacileds[i][2];
value.g = vyrovnavacileds[i][3];
value.b = vyrovnavacileds[i][4];
serial1.print(from);
serial1.print(";");
serial1.print(to);
serial1.print(";");
serial1.print(value.r);
serial1.print(";");
serial1.print(value.g);
serial1.print(";");
serial1.println(value.b);
for(int led = from; led < + 1; led++)
{
led.set_crgb_at(led, value);
}
}
interval = 0;
led.sync();
}
else
{
serial1.print("che:" );
serial1.print(check);
serial1.print(";");
serial1.println(reccheck);
}
}
}
thanks.
(sorry english)
the following:
are not assignment statements, single equal sign. that's starting point...
code: [select]
vyrovnavacileds[interval][0] == from;
vyrovnavacileds[interval][1] == to;
vyrovnavacileds[interval][2] == r;
vyrovnavacileds[interval][3] == g;
vyrovnavacileds[interval][4] == b;
are not assignment statements, single equal sign. that's starting point...
Arduino Forum > Using Arduino > Programming Questions > Cannot write to 2D int array
arduino
Comments
Post a Comment