Project overview: (This is programming prob not a xbee prob), I have 5 int values which i want wirelessly send to another xbee. "My problem is how to give hexvalues(0x4E) in Serial.write() when i have an integers values(say current, voltage etc) ??"
What i did till now:
void loop(){
int RP= 1391;
int AP= 1581;
int PF= 88;
int V= 25500;
int I= 62;
char RPh= char(bitDividerhigh(RP));
char RPl= char(bitDividerlow(RP));
char APh= char(bitDividerhigh(AP));
char APl= char(bitDividerlow(AP));
char PFh= char(bitDividerhigh(PF));
char PFl= char(bitDividerlow(PF));
char Vh= char(bitDividerhigh(V));
char Vl= char(bitDividerlow(V));
char Ih= char(bitDividerhigh(I));
char Il= char(bitDividerlow(I));
Serial.write(0x7E);
Serial.write((byte) 0x0);
Serial.write(0x18);
Serial.write(0x10);
Serial.write(0x01);
Serial.write((byte) 0x0);
Serial.write((byte) 0x0);
Serial.write((byte) 0x0);
Serial.write((byte) 0x0);
Serial.write((byte) 0x0);
Serial.write((byte) 0x0);
Serial.write((byte) 0x0);
Serial.write((byte) 0x0);
Serial.write(0xFF);
Serial.write(0xFE);
Serial.write((byte) 0x0);
Serial.write((byte) 0x0);
Serial.write(RPh);// issue here
Serial.write(RPl);// issue here
Serial.write(APh);// issue here
Serial.write(APl);// issue here
Serial.write(PFh);// issue here
Serial.write(PFl);// issue here
Serial.write(Vh);// issue here
Serial.write(Vl);// issue here
Serial.write(Ih);// issue here
Serial.write(Il);// issue here
long sum= 0x10 + 0xFF + 0xFF + 0xFF + 0xFE + RPh + RPl + APh + APl + PFh + PFl + Vh + Vl + Ih + Il;
Serial.write( 0xFF - (sum&0xFF));
delay(100);
}
int bitDividerhigh(int input){
int b= 65280;
int c= input&b;
int d= c>>8;
return d;
}
int bitDividerlow(int input){
int e= 255;
int f= input&e;
return f;
}
Issue: I have indicated as comments in the code where i think, the data type i gave isn't the same as what its supposed to be. "Simply put just tell me, how to convert this integer values values into RF data that's perfectly compatible with Serial.write()??"
Note: I am from electrical background, so much programming technical talk can confuse me , please try to provide some code to solve my issue( My coding knowledge can be judged from above code, its not a copy&paste). Thank you !!!