Подключаем выход приемника нужного канала к AnalogIn0, светодиод между DigitalI/O13 и gnd не забыв про резистор.
Код:
int PPMin1 = 14; // connect the desired channel (PPM signal) from your RC receiver to analog pin 0 (pin 14) on Arduino.
int ledPin13 = 13; //светодиод здесь
int RCval1; // store RC signal pulse length
int adj_val1; // map that value to be between 0-255
void setup()
{
Serial.begin(9600); //serial library start
pinMode(ledPin13, OUTPUT);
pinMode(PPMin1, INPUT); //Pin 14 as input
}
void loop()
{
RCval1 = pulseIn(PPMin1, HIGH, 20000); //read RC channel 1
adj_val1 = map(RCval1, 630, 1125, 0, 255); // my observed RC values are between 630-1125.. these might need to be changed, depending on your RC system.
if (RCval1 < 1500)
{
digitalWrite(ledPin13, LOW);
}
else
{
digitalWrite(ledPin13, HIGH);
}
Serial.print ("val1: ");
Serial.print (RCval1); // if you turn on your serial monitor you can see the readings.
Serial.print (" ");
Serial.print ("adjusted: ");
Serial.print (adj_val1);
Serial.println (" ");
}
Оригинал кода здесь.
Видео: