-
Notifications
You must be signed in to change notification settings - Fork 0
/
Code
77 lines (58 loc) · 1.44 KB
/
Code
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
/*
What you'll need:
- Arduino Uno
- Continuous Rotation Servo
- RGB LED
- Plastic Egg Toys
- Googly Eyes
- Jumping wires
*/
//.............................................................................................................................................................................................................................................................
//Arduino Code
#include <Servo.h>
// Servo variable
Servo myservo;
// LEDs pins
const int redLEDPin = 6;
const int greenLEDPin = 7;
const int blueLEDPin = 5;
// Delay times
const int shortDelay = 80;
const int longDelay = 250;
void setup() {
// Attach servo to pin 9
myservo.attach(9);
// Set LED pins as outputs
pinMode(redLEDPin, OUTPUT);
pinMode(greenLEDPin, OUTPUT);
pinMode(blueLEDPin, OUTPUT);
}
void loop() {
rotateServo(100); // Rotate servo
// Pink Color
setColor(255, 0, 255);
delay(shortDelay);
turnOffLEDs();
delay(longDelay);
// Green Color
setColor(0, 255, 50);
delay(shortDelay);
turnOffLEDs();
delay(longDelay);
// White Color
setColor(255, 255, 255);
delay(shortDelay);
turnOffLEDs();
delay(longDelay);
}
void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redLEDPin, redValue);
analogWrite(greenLEDPin, greenValue);
analogWrite(blueLEDPin, blueValue);
}
void turnOffLEDs() {
setColor(0, 0, 0); // Turn off LEDs
}
void rotateServo(int angle) {
myservo.write(angle); // Rotate servo
}