Hi friends,
I have to generate insect flapping motion to my servomotors. Let say flapping frequency (1hz, 2hz, 3hz,4hz 5 Hz) and flapping amplitude (i.e up and down motion of the wing: -90 to 0 to 90 deg.).
Seems I have to create sinewave to my servo (at certain frequency with flapping amplitude)
In this context, I used sweep option in arduino. pls see the two code below.
Q.1) Can someone explain the difference b/w these codes?
Q.2) Helpful if someone guide me how to create sine wave motion (i.e insect flapping motion (up & down) with certain frequency)). Thanks in Advance.
Code.1
#include <Servo.h>
Servo servo1;
int servoPos =0;
void setup()
{
servo1.attach(9);
}
void loop ()
{
for(servoPos = 0; servoPos < 180; servoPos++)
{
servo1.write(servoPos);
delay(10);
servo1.write(180);
}
for(servoPos = 180; servoPos > 0; servoPos--)
{
servo1.write(servoPos);
delay(10);
}
}
Code.2
#include <Servo.h>
Servo servoMain;
void setup()
{
servoMain.attach(9);
}
void loop()
{
servoMain.write(0);
delay(1000);
servoMain.write(90);
delay(1000);
servoMain.write(180);
delay(500);
servoMain.write(180);
delay(1000);
servoMain.write(90);
delay(50);
}