Hi All,
I'm trying to code a joystick to control pitching of a quadcopter. I want to put the 2 analogWrite commands inside of the same if statement, if that is possible. If it isn't possible, I'll need to find an alternative I suppose...
When I try to compile the code the way I have it, it gives the error of no semicolon, but if I put a semicolon, the if statement will not include the second analogWrite command...
I'm also trying to declare the analog number value 2 (not a pin) as the word "slow" I'm not getting a compiler error so I think it works but I'm wondering why doesn't the arduino thing that digital pin 2 is called "slow"?
Anyway here is the code
<
int x_plane = A1;
int y_plane = A0;
int x_pos;
int y_pos;
int sepin = 11;
int swpin = 9;
int nepin = 10;
int nwpin = 6;
int hover=40;
int fast=100;
int slow=2;
Hi Paul,
Thank you for your comment. I just now put curly brackets on the if statements like this:
<
if (x_pos<300){
analogWrite(swpin && nwpin, slow)
analogWrite(sepin && nepin, fast);
}
Replace the < before your code by ** **[code]** **
Replace the > after your code by ** **[/code]** **
Your code does not compile due to missing semi-colons; fix that first
The IDE provides a function to properly indent your code; IDE menu tools -> autoformat. After fixing the semi-colons and doing an autoformat, you will see
The fact that the second analogWrite after an if is not indented indicates that it's not part of the code that get executed conditionally. As @Paul_KD7HB said, embed what needs to be conditionally executed between { and }.
jimLee:
Once you read the joystick, how are you planning on using that to control the quadcopter?
-jim lee
Hi Jim Lee,
This joystick will control only the pitch of the quadcopter, and I will code another joystick for elevation and yaw. I was planning on using a separate arduino or other circuit board in the quadcopter to wirelessly connect to the one that has joysticks connected to it.