i have been trying to use virtual wire library to control a LED by using a push button mounted on a different arduino , the problem is that the LED keep blinking after i press the push button for the first time instead of turning on then it stop responding .
P.S:(i want the LED to turn off or on every time i press the push button)
sender code
#include <VirtualWire.h>
char *controller;
int a;
int b;
int c;
void setup() {
pinMode(7,INPUT);
pinMode(8,INPUT);
pinMode(9,INPUT);
vw_set_ptt_inverted(true); //
vw_set_tx_pin(12);
vw_setup(4000);
}
void loop(){
b = digitalRead(8);
a = digitalRead(7);
c = digitalRead(9);
if (a == HIGH){
controller="0";
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
}
if (b == HIGH){
controller="1";
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
}
if (c == HIGH){
controller="2";
vw_send((uint8_t *)controller, strlen(controller));
vw_wait_tx(); // Wait until the whole message is gone
}
}
receiver code
#include <VirtualWire.h>
int a=0;
void setup()
{
vw_set_ptt_inverted(true); // Required for DR3100
vw_set_rx_pin(12);
vw_setup(4000); // Bits per sec
pinMode(13, OUTPUT);
pinMode(11, OUTPUT);
pinMode(9, OUTPUT);
vw_rx_start(); // Start the receiver PLL running
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
if(buf[0]=='0'){
digitalWrite(13, !digitalRead(13));
}
if (buf[0] =='1'){
digitalWrite(11, !digitalRead(11));
}
if (buf[0] =='2'){
digitalWrite(9, !digitalRead(9));
}
}
}
thanks for you help and i apologies for my stupidity.