-
Notifications
You must be signed in to change notification settings - Fork 0
/
finalServoOrnithopter.ino
49 lines (38 loc) · 1.03 KB
/
finalServoOrnithopter.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 8 Nov 2013
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
const int rightWingPin = 5;
const int leftWingPin = 3;
Servo rightWing;
Servo leftWing;
unsigned long previousMillis = 0;
const long interval = 100;
int counter = 0;
int pos = 0; // variable to store the servo position
void setup() {
rightWing.attach(rightWingPin); // attaches the servo on pin 9 to the servo object
rightWing.write(90);
leftWing.attach(leftWingPin); // attaches the servo on pin 9 to the servo object
leftWing.write(90);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
if (counter % 2 == 0) {
rightWing.write(30)fest;
leftWing.write(150);
counter++;
} else {
rightWing.write(160);
leftWing.write(30);
counter++;
}
}
}