qualcuno sa come si fa a dividere i byte contenuti in un frame inviato da un xbee?
per esempio: io ho due xbee e un arduino, uno dei xbee è in modalià API e fa da trasmettitore, mentre un'altro è in modalità AT ed è montato sull'arduino e fa da ricevitore. Il trasmettitore manda un frame contenente i seguenti byte [BC D3 A1], come faccio ne ricevitore a salvare i tre byte in 3 celle diverse?
const byte numPins = 7;
const byte numBytes = 3;
byte pilot1[] = {13, 12, 11, 10, 9, 8, 7};
byte pilot2[] = {6, 5, 4, 3, 2, 14, 15};
byte pilot3[] = {16, 17, 18, 19, 20, 21, 22};
byte frame[numBytes];
void setup() {
Serial.begin(9600);
for (int b = 2; b <= 22; b++)
{
pinMode(b, OUTPUT);
digitalWrite(b, LOW);
}
}
void loop() {
while (Serial.available() > 0) { // Do nothing until serial input is received
for (byte d = 0; d <= 2; d++) { //try to load the 3 bytes in the array
frame[d] = Serial.read();
}
for (byte i = 0; i < numPins; i++) {
byte state = bitRead(frame[0], i); //converting single hex byte to bin
digitalWrite(pilot1[i], state);
Serial.print(state);
}
Serial.println();
for (byte i = 0; i < numPins; i++) {
int c = 0;
byte state1 = bitRead(frame[1], i);
digitalWrite(pilot2[c], state1);
c++;
Serial.print(state1);
}
Serial.println();
for (byte i = 0; i < numPins; i++) {
byte state2 = bitRead(frame[2], i);
digitalWrite(pilot3[i], state2);
Serial.print(state2);
}
}
}
questo è il programma che ho creato, in pratica fa tre letture e salva ogni lettura in una cella, solo che quando faccio il serial print, anzi che darmi solo tre valori me ne da 9, come mai?