i've saved data arriving trough i2c in array , access single values. when save , print array values function saving them values fine, when try access them outside function "double" value meaning in array there value "0" memorized before every valued saved.
int bytearray[100]; boolean horicevutodati = false; void setup() { serial.begin(9600); // start serial output wire.begin(slave_address); wire.onreceive(receivedatalist); } void loop() { delay(1000); horicevutodati = dallenotealmotorino(horicevutodati); } void receivedatalist(int numbyte){ int = 0; while(wire.available() > 0){ for(i=0; < 100; i++){ bytearray[i] = wire.read(); if (bytearray[i] == 255){ break; } else{ serial.println(bytearray[i]); i++; } }; } boolean dallenotealmotorino (boolean horicevutodati) { while (horicevutodati == true) { serial.print("byte[0] "); serial.println(bytearray[0]); serial.print("byte[1] "); serial.println(bytearray[1]); serial.print("byte[2] "); serial.println(bytearray[2]); serial.print("byte[3] "); serial.println(bytearray[3]); serial.print("byte[4] "); serial.println(bytearray[4]); return horicevutodati = false; } }
via i2c i'm transmitting {0,2,5,4,...}, when dallenotealmotorino runs i'm expecting see 0, 2, 5, 4... instead 0 0 0 2 0 5 0 4... every number has 0 before. looking around think might have turned byte array array of pointers though i'm not sure how did since i'm not passing array parameter anywhere. don't understand 0 before value or how can access value. don't understand happening.
i'm leaving here in case else had problem. used
serial.print("value "); serial.println(bytearray[i]); serial.print("pointer address"); serial.println((int)&bytearray[i]);
to check on pointer adresses , saw values i2c got memorized every 4bytes while function searched them every 2 bytes. understand c (and arduino) let use variable number memorize int , think problem.
Comments
Post a Comment