Hello guys,
I would like to build a code that does the following on Arduino Pro Mini:
- gets PWM input from standard RC Receiver.
- reads analog voltage from A0.
- commands a standard RC servo on D9.
The servo commands should be as follows:
- if A0 voltage > 50% (2.5V) then servo PWM == Rx read PWM.
- if Ao voltage <= 50% (2.5V) then servo PWM == const, lets say 10 degrees as an example.
I have followed the Arduino site example with a small change and can run the servo from a pot, and when the pot is at less than 50%, lock the servo in a predefined position, using this simple code:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
if (val<90)
myservo.write(50); // sets the servo position according to the scaled value
else
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
my question is how do i proceed from here in order to read PWM value from my RC receiver, and store it in a variable.
i believe that once i know that, i will be able to figure out everything else.
Can anyone offer assistance please?
thanks for your help.