int servoPin1 = A4;
int servoPin2 = A5;
Servo myServo1;
Servo myServo2;
int servoPos1 = 0;
int servoPos2 = 180;
int angle = 0;
int wing_speed_up = 7;
int wing_speed_down = 3;
int wing_up = 120;
int wing_down = 70;
int fly_permission = 0;
void setup() {
myServo1.attach( A4 );
myServo2.attach( A5 );
Particle.function("myServo1", servoControl1);
Particle.function("myServo2", servoControl2);
Particle.subscribe("melikey", event_driven);
Particle.variable( "servoPos1" , &servoPos1 , INT );
Particle.variable( "servoPos2" , &servoPos2 , INT );
}
void loop() {
if(fly_permission == 1)
{
delay(3000);
for (int i=1; i < 12; i++)
{
for(angle = wing_down; angle < wing_up; angle++)
{
myServo1.write(angle);
myServo2.write(180 - angle);
delay(wing_speed_up);
}
for(angle = wing_up; angle > wing_down; angle--)
{
myServo1.write(angle);
myServo2.write(180 - angle);
delay(wing_speed_down);
}
}
int servoControl1(String command)
{
int newPos1 = command.toInt();
servoPos1 = constrain( newPos1, 0 , 180);
myServo1.write( servoPos1 );
return 0;
}
int servoControl2(String command)
{
int newPos2 = command.toInt();
servoPos2 = constrain( newPos2, 0 , 180);
myServo2.write( servoPos2 );
return 0;
}
void event_driven(const char *event, const char *data)
{
fly_permission = 1;
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .