Hey Guys, new to Arduino programming. Got a 433mhz wireless transmit and receive program working.
See my RECEIVE code below
I need the 2 pins (Digital2 and 3) to be always on HIGH and then when it receives either a 2 or 3, will set the respective pins to LOW. There is a problem if the signal might drop out for a split second, the pins will be placed in the last received state (either HIGH or LOW), so therefore to be safe it needs to be on HIGH even if signal does drop for a second.
I tried placing the 2 lines ( digitalWrite(2, HIGH); and digitalWrite(3, HIGH) outside the "if" block but the pins always stay on HIGH. It doesn't change.
Is someone able to point me in the right direction?
#include <RH_ASK.h>
#include <SPI.h>
RH_ASK driver;
void setup() {
Serial.begin(9600); // Debugging only
if (!driver.init())
Serial.println("init failed");
}
void loop() {
int Mode = 0;
//buf is a pointer to the received bytes--------------------------
uint8_t buflen = 1;
uint8_t buf[buflen];
if (driver.recv(buf, &buflen)) // Non-blocking
{
int i;
// DEBUG Message with a good checksum received, dump it.
//Enable 5v pull up on Digital Pin 2 and 3
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
Serial.print("Mode: ");
Serial.println(*buf);
Mode = buf[0];
if (Mode == 2) { //If Mode 2, set Pin 2 to Low 0v
digitalWrite(2, LOW);
}
if (Mode == 3) { //If Mode 3, set Pin 3 to Low 0v
digitalWrite(3, LOW);
}
}
}