I am using a pair of HC-12 and have the functionality with one button on the transmitter working where the receiver recognizes the unique code I am sending, but when I add a second button the transmitter is still only send the code for the first button. Can anyone shed some light to why its not sending the correct code?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //RX, TX
int buttonPinFWD = 7;
int buttonPinREV = 8;
boolean onOff = 0;
void setup() {
pinMode(buttonPinFWD, INPUT);
pinMode(buttonPinREV, INPUT);
pinMode(onOff, OUTPUT);
mySerial.begin(9600);
Serial.begin(9600);
}
void loop() {
int buttonStateFWD = digitalRead(buttonPinFWD);//read button state FWD
int buttonStateREV = digitalRead(buttonPinREV);//read button state REV
if(buttonStateFWD == HIGH){//if button is down
mySerial.println(1111);//send unique code to the receiver to turn on. In this case 1111
onOff = 1;//set boolean to 1
}
if(buttonStateFWD == LOW && onOff == 0);{//Verifier to send off signal once
mySerial.println(0000);//send unique code to the receiver to turn off. In this case 0000
}
if(buttonStateREV == HIGH){
mySerial.println(5555);
onOff = 1;
}
if(buttonStateREV == LOW && onOff == 0){
mySerial.println(0000);
}
delay(100);//delay little for better serial communication