Hi everyone
i got 2 set of arduino codes to use to make the brushless rotors spin .
The first set of codes which can be found in the example (knob) can make it spin.
However, the second set of code cant make it spin, although there is no error. it is above the same as the first set but added with
some other codes to interface with gyro sensors. can anyone help me solve the 2nd set of code ?
The second set of codes look something like this :
Servo myservo1;
Servo myservo2;
int potpin =0;
int gyropin = 1;
int joypin= 2;
int levelpin= 3;
int val1;
int val2;
int val3;
int val4;
int val5;//variable to read the main rotor gyro
int sum1;
int sum2;
void setup()
{
myservo1.attach(9);//control tail motor through pin 9
myservo2.attach(10);//control main rotor through pin 10
}
void loop()
{
val1=analogRead(potpin);
//(value between 0 and 1023) - read the value of the potentiometer
val1= map(val1,0,1023,0,179);
//(value between 0 and 180)-scale it to use with servo
val2=analogRead(gyropin);
//(value between 0 and 1023)- to read the value of the potentiometer
val2=map(val2,0,1023,0,179);
//(value between 0 and 180)-scale it to use with servo
val3=analogRead(joypin);
//(value between 0 and 1023)- to read the value of the potentiometer
val3=map(val3,0,1023,0,179);
//(value between 0 and 180)-scale it to use with servo
val5 = analogRead(levelpin);
// read the potentiometer(value between 0 and 1023)
val5 = map(val5,0,1023,0,179);
//(value between 0 and 180)-scale it to use with servo
val4 = 1500 - val3;
sum1 = (0.15 *val4)+ (0.7 * val1) + (0.15 * val2);
sum2 = (0.25 * val5)+(0.75 * val1);//mixing
myservo1.write(sum1);
//set the servo position according to the scaled value
delay(15);
myservo2.write(sum2);
//set the main rotor to the potentiometer
delay (15);
}