-
Notifications
You must be signed in to change notification settings - Fork 0
/
servo-example.ino
105 lines (63 loc) · 1.46 KB
/
servo-example.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <Servo.h>
Servo headMotor;
Servo rightMotor;
Servo leftMotor;
/*
Morse Code Key:
dot = LED on for 100 ms, then LED off for 100 ms
dash = LED on for 300 ms, then LED off for 100 ms
End of Letter = LED off for 1000 ms
End of Word = LED off for 2000 ms
Challenges:
1) Move head to using the button
2) Check arms are working too
3) Calibrate our robot (arms straight out, head looking forward)
4) Move arms and head when you press the button
5) Combine the lights, buzzer and motors using functions
6) Make your robot dance however you want
*/
void setup() {
pinMode(8,INPUT_PULLUP);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(13,OUTPUT);
pinMode(9,OUTPUT); //- head
pinMode(10,OUTPUT); //- right arm
pinMode(11,OUTPUT); //- left arm
headMotor.attach(9);
rightMotor.attach(10);
leftMotor.attach(11);
headMotor.write(90);
rightMotor.write(90);
leftMotor.write(90);
}
void on() {
digitalWrite(7,HIGH);
digitalWrite(13,HIGH);
tone(6,261);
delay(100);
tone(6,523);
delay(100);
}
void off() {
digitalWrite(7,LOW);
digitalWrite(13,LOW);
noTone(6);
}
void loop() {
if (digitalRead(8) == LOW) {
on();
delay(1000);
rightMotor.write(180);
leftMotor.write(0);
headMotor.write(180);
delay(2000);
rightMotor.write(0);
leftMotor.write(180);
headMotor.write(90);
delay(2000);
}
else {
off();
}
}