Go Down

Topic: Receiver Output to Control PWM Value (Read 439 times) previous topic - next topic

QAMember

I need the throttle pin of an R/C receiver to interface with the Arduino and constrain, I believe, between two values. The following code:

int pinArray[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
int count = 0;
void setup() {
  Serial.begin(9600);
  for (count=0;count<13;count++) {
    pinMode(pinArray[count], OUTPUT);
  }
  pinMode(0, INPUT);
 
  int eraser = 7;    //111
  TCCR0B &= ~eraser;    //sets timers to 000
  TCCR1B &= ~eraser;
  TCCR2B &= ~eraser;
  TCCR3B &= ~eraser;
  TCCR4B &= ~eraser;
  int prescaler = 1;    //1 being highest frequency
  TCCR0B |= prescaler;    //sets timers to 1
  TCCR1B |= prescaler;
  TCCR2B |= prescaler;
  TCCR3B |= prescaler;
  TCCR4B |= prescaler;
}

int x = analogRead(0) / 1023;    //percentage of input
int c = x * 10000 + 8000;    //range defined

void loop() {
  float a = 128.0;
  float b = 128.0;
  float c;
  float d = 2.0;
  float e = 18.3;    //offset

{
  int value = a - b * abs(sin(d*PI*millis()/c));
  analogWrite(2,value);

{
  int value = a - b * abs(sin(d*PI*millis()/c));
  analogWrite(3,value);
}
{
  int value = a - b * abs(sin(d*PI*millis()/c));
  analogWrite(4,value);
}
{
  int value = a - b * abs(sin(d*PI*millis()/c));
  analogWrite(5,value);
}
{
  int value = a - b * abs(sin(d*PI*millis()/c));
  analogWrite(6,value);
}
{
  int value = a - b * abs(sin(d*PI*millis()/c));
  analogWrite(7,value);
}
{
  int value = a - b * abs(sin(d*PI*millis()/c));
  analogWrite(8,value);
}
{
  int value = a - b * abs(sin(d*PI*millis()/c));
  analogWrite(9,value);
}
{
  int value = a - b * abs(sin(d*PI*millis()/c));
  analogWrite(10,value);
}
{
  int value = a - b * abs(sin(d*PI*millis()/c));
  analogWrite(11,value);
}
{
  int value = a - b * abs(sin(d*PI*millis()/c));
  analogWrite(12,value);
}
{
  int value = a - b * abs(sin(d*PI*millis()/c));
  analogWrite(13,value);
}
}

The analog input pin should be zero, while the PWM outputs are from 2 to 13. Float C is the variable value. Is this:
"
int x = analogRead(0) / 1023;    //percentage of input
int c = x * 10000 + 8000;    //range defined
"
-all that is required for one channel PPM control?

afremont

You have some issues that need to be addressed:
1) you are dividing by "c" which has not been initialized
2) you are creating a variable "x" that is an int and dividing analogRead() by 1023, that's pretty much always going to be 0

What board are you using?
Experience, it's what you get when you were expecting something else.


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy