Go Down

Topic: (solved) problem reading data from rc receiver (Read 1 time) previous topic - next topic

groundfungus

I cleaned it up a bit.  This should work.

Code: [Select]
const byte ch1 = 3;
const byte led = 13;

void setup() {
  pinMode(ch1, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int width = pulseIn(ch1, HIGH, 30000);
  Serial.print("Channel 1:  ");
  Serial.println(width);       
  if(width > 1800) {
     digitalWrite(led, HIGH);
  }

Serial.println();
delay(100);
}

jeremybgilbert

#16
Oct 25, 2013, 03:27 am Last Edit: Oct 25, 2013, 03:31 am by jeremybgilbert Reason: 1
thank you!!!! but i did have to make a change. i changed it to pin 11 as the led output and it works! maybe something is wrong with pin 13 on my board here is the finished code i added a line to turn the led back off

Code: [Select]
const byte ch1 = 3;
const byte led = 11;

void setup() {
  pinMode(ch1, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int width = pulseIn(ch1, HIGH, 30000);
  Serial.print("Channel 1:  ");
  Serial.println(width);       
  if(width > 1990) {
     digitalWrite(led, HIGH);
  }
     if(width < 1800) {
     digitalWrite(led, LOW);
  }
}



groundfungus

Yeah, I realized that as soon as you said the led wasn't coming on.  Congrats.

jeremybgilbert

thank you so much for your help! you are awesome lol now im going to edit it to have three channels since i have three spare channels on my receiver.

Go Up