-
Notifications
You must be signed in to change notification settings - Fork 0
/
uselessbox.ino
128 lines (111 loc) · 2.67 KB
/
uselessbox.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
Useless Box by Oscar Gonzalez
August 2016 - BricoGeek.com
*/
#include <Servo.h>
Servo myservo;
#define SERVO_PIN 9
#define SERVO_MIN 15
#define SERVO_MAX 100
#define SWITCH_PIN 6
static void movFunc01() {
Serial.println("Function 01");
delay(400);
myservo.write(55);
delay(800);
for (int pos = SERVO_MAX-SERVO_MIN; pos <= SERVO_MAX ; pos += 1) {
// in steps of 1 degree
myservo.write(pos);
delay(15);
}
myservo.write(SERVO_MIN);
}
void movFunc02() {
Serial.println("Function 02");
delay(400);
myservo.write(55);
delay(1000);
for (int pos = SERVO_MAX-SERVO_MIN; pos <= SERVO_MAX ; pos += 1) {
// in steps of 1 degree
myservo.write(pos);
delay(25);
}
myservo.write(SERVO_MIN);
}
void movFunc03() {
Serial.println("Function 02");
delay(200);
for (int pos = SERVO_MIN; pos <= 60 ; pos += 1) {
// in steps of 1 degree
myservo.write(pos);
delay(10);
}
delay(900);
for (int pos = 60; pos <= SERVO_MAX ; pos += 1) {
// in steps of 1 degree
myservo.write(pos);
delay(20);
}
for (int pos = SERVO_MAX; pos >= SERVO_MIN ; pos -= 1) {
// in steps of 1 degree
myservo.write(pos);
delay(45);
}
myservo.write(SERVO_MIN);
}
void movFunc04() {
delay(400);
for (int j=0 ; j<5 ; j++)
{
myservo.write(SERVO_MIN+20); delay(60);
myservo.write(SERVO_MIN); delay(60);
}
delay(550);
for (int pos = SERVO_MIN; pos <= SERVO_MAX ; pos += 1) {
// in steps of 1 degree
myservo.write(pos);
delay(2);
}
delay(200);
for (int pos = SERVO_MAX; pos >= SERVO_MIN ; pos -= 1) {
// in steps of 1 degree
myservo.write(pos);
delay(10);
}
}
void movFunc05() {
for (int pos = SERVO_MIN; pos <= SERVO_MAX ; pos += 1) {
// in steps of 1 degree
myservo.write(pos);
delay(8);
}
for (int pos = SERVO_MAX; pos >= SERVO_MIN ; pos -= 1) {
// in steps of 1 degree
myservo.write(pos);
delay(10);
}
}
void setup() {
pinMode(SERVO_PIN, OUTPUT);
pinMode(SWITCH_PIN, INPUT_PULLUP);
Serial.begin(9600);
myservo.attach(SERVO_PIN);
myservo.write(SERVO_MIN);
randomSeed(analogRead(0));
Serial.println("Useless Box");
}
void loop() {
if (!digitalRead(SWITCH_PIN))
{
int rnd = random(0, 5);
switch (rnd)
{
case 0: { movFunc01(); }; break;
case 1: { movFunc02(); }; break;
case 2: { movFunc03(); }; break;
case 3: { movFunc04(); }; break;
case 4: { movFunc05(); }; break;
}
delay(1000);
}
}