I try to have a 5 digital channels remote with 2 arduinos and RF 433MHz (Tx/Rx) Modules
I decided to code the button's states with a binary number (each bit is a button's state). An easy way to add some buttons if I need it.
This sketch code and send via serial the binary value, but I need to send it via RF communication, and I'm stuck here.
I think this code to send via RF is ok
char msg[7] = {BStates, BIN};
vw_send((uint8_t *)msg, 7);
vw_wait_tx(); // Wait until the whole message is gone
delay(1000);
But I can't find how to to receive it and decode to have 5 digital outputs...
There is the Tx code
// declare names and pins
int Button1 = 4;
int Button2 = 5;
int Button3 = 6;
int Button4 = 7;
int Button5 = 8;
void setup() {
// initialize serial at 9600 bps
Serial.begin(9600);
// input mode for inputs
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
pinMode(Button3, INPUT);
pinMode(Button4, INPUT);
pinMode(Button5, INPUT);
}
void loop() {
// code each state for binary word (DEC to BIN)
byte B1state = (digitalRead(4)); // 1st bit
byte B2state = (2 * digitalRead(5)); //2nd bit
byte B3state = (4 * digitalRead(6)); // 3rd bit
byte B4state = (8 * digitalRead(7)); // 4th bit
byte B5state = (16 * digitalRead(8)); // 5th bit
byte BStates = (B1state + B2state + B3state + B4state + B5state); // create 5 bits word
Serial.println(BStates, BIN); //send the 5 bits word
delay(10); // delay between loops
char msg[7] = {BStates, BIN};
vw_send((uint8_t *)msg, 7);
vw_wait_tx(); // Wait until the whole message is gone
delay(1000);
}
I tried some sketch to receive this code but nothing works...
Thanks for your help..