After some encouragement I received here I thought I would try my hand at writing some code for a project I am working on. In a nutshell a 6-channel RC PPM Encoder using a Joystick and Slider. All analog Pots and a few switches. What I am not sure about is how to physically use the library. It consist of two files, a cpp and h file. First try is I opened the cpp file and tried to figure out how to insert my code. Got no where. Some said start with the LoopBack example and go from there. It finally hit me how to bring in the PPM files with the Include statement, duh? Sorry I am a newb.
OK anyway I have got a decent start on a sketch I think, but stuck and need some help. Code below. What is below does compile, and comes with Warning a Var not being used. It loads, and does generate a 6 channel PPM string. So as you look at the code, all my work is everything before the first WRITE instruction is where I got lost. Not even sure what I did write works like I think it should. So before the WRITE commands is where I think I declared my variables, assigned an Analog pin, then with the begin function I assume that means to read the Analog voltage. I hope I have it right up to this point.
OK my first stumbling block is to replace the current Write commands that now are just writing set numbers I put in there to verify on a Scope it did what I think it should and does. Problem is I do not know the command or syntax to do that. Would it be:
PPMOut.analogWrite(A0);
or
PPMOut.analogWrite(Ailerons);
or
PPMOut.write(1, A0);
or something else?
Lastly everything below the Write Commands is Greek to me and is where the WARNING comes from the compiler and it reads:
PULSE_TEST:32: warning: unused variable 'i'
int i, num;
^
PULSE_TEST:32: warning: variable 'num' set but not used
int i, num;
All the code in Red I do not know how to work with that came with the Loopback example. I know it updates a register some where and only changes if the analog input changes between pulses. I know I need it, but I got the code messed up. So any help or pointers is appreciated.
OK anyway I have got a decent start on a sketch I think, but stuck and need some help. Code below. What is below does compile, and comes with Warning a Var not being used. It loads, and does generate a 6 channel PPM string. So as you look at the code, all my work is everything before the first WRITE instruction is where I got lost. Not even sure what I did write works like I think it should. So before the WRITE commands is where I think I declared my variables, assigned an Analog pin, then with the begin function I assume that means to read the Analog voltage. I hope I have it right up to this point.
OK my first stumbling block is to replace the current Write commands that now are just writing set numbers I put in there to verify on a Scope it did what I think it should and does. Problem is I do not know the command or syntax to do that. Would it be:
PPMOut.analogWrite(A0);
or
PPMOut.analogWrite(Ailerons);
or
PPMOut.write(1, A0);
or something else?
Lastly everything below the Write Commands is Greek to me and is where the WARNING comes from the compiler and it reads:
PULSE_TEST:32: warning: unused variable 'i'
int i, num;
^
PULSE_TEST:32: warning: variable 'num' set but not used
int i, num;
All the code in Red I do not know how to work with that came with the Loopback example. I know it updates a register some where and only changes if the analog input changes between pulses. I know I need it, but I got the code messed up. So any help or pointers is appreciated.
Code:
#include <PulsePosition.h>
// From Pulse Position Library
// 6-channel PPM Encoder
PulsePositionOutput PPMOut(FALLING); //declare PPM signal out, 6-channels, falling edge.
PulsePositionInput Alerons; //declare ch 1
PulsePositionInput Rudder; //declare ch 2
PulsePositionInput Throttle; //declare ch 3
PulsePositionInput Elevators; //declare ch 4
PulsePositionInput Gear; //declare ch 5
PulsePositionInput Aux; // declare ch 6
void setup() {
PPMOut.begin(10); // Start 6-Channel PPM OutPut
Alerons.begin(A0); // Start reading Ailerons
Rudder.begin(A1); // Start reading Rudder
Throttle.begin(A2); //Start reading Throttle
Elevators.begin(A3); // Start reading Elevators
Gear.begin(A4); // Start reading Gear
Aux.begin(A5); // Start reading Aux
PPMOut.write(1, 2200);// [COLOR="#FF0000"]need to change all this to write the analog inputs[/COLOR]
PPMOut.write(2, 2200);
PPMOut.write(3, 2200);
// slots 4 and 5 will default to 1500 us
PPMOut.write(6, 2200);
}
[COLOR="#FF0000"]int count=0;
void loop() {
int i, num;
// Every time new data arrives, simply print it
// to the Arduino Serial Monitor.
num = Alerons.available();
num = Rudder.available();[/COLOR]
}
Last edited: