I m a little bit confused . I am making an rc plane and I need to control an 120 degree servo with two buttons
When button1 is being pressed the motor should go to 120
When button2 is being pressed the motor should go to 0
And when no button isbeing pressed the motor should stay on 60 ° but instead it goes full right no matter what button I press . Is there an issue with the arduino servo library and the HC12 and what can I do about it ?
Reciever :
#include <SoftwareSerial.h>
#include <Servo.h>
int ROT ;
Servo myservo;
SoftwareSerial HC12(10, 11);
void setup() {
Serial.begin(9600);
HC12.begin(9600);
myservo.attach(9);
myservo.write(60);
}
void loop() {
while ( HC12.available() ) {
ROT = HC12.read();
}
Serial.println(ROT);
if ( ROT == 1){
myservo.write(0);
}
else if ( ROT == 2 ){
myservo.write(120);
}
else {
myservo.write(60);
}
}
Transmitter :
#include <SoftwareSerial.h>
int LEFT ;
int RIGHT;
int ROT = 0 ;
SoftwareSerial HC12(10, 11);
void setup() {
Serial.begin(9600);
HC12.begin(9600);
}
void loop() {
LEFT = digitalRead(A0);
RIGHT = digitalRead(A1);
if (RIGHT == HIGH ){
ROT = 2;
}
else if ( LEFT == HIGH ){
ROT = 1;
}
else {
ROT = 0 ;
}
HC12.write(ROT);
}