-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsweep.ino
More file actions
69 lines (63 loc) · 1.79 KB
/
sweep.ino
File metadata and controls
69 lines (63 loc) · 1.79 KB
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
/* 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>
Servo theBlock; // create servo object to control a servo
// twelve servo objects can be created on most boards
boolean spinMe = false;
boolean opened = false;
int posBlock = 0; // variable to store the servo position
//pin assignments
int fan = 8;
int servo = 9;
int inputLed = 11;
void setup() {
theBlock.attach(servo); // attaches the servo on pin servo to the servo object
pinMode(fan, OUTPUT); //output that controls fan on pin fan
pinMode(inputLed, INPUT); //Input to controls all on pin inputLed
}
void loop() {
getInput();
saltTheEarth();
}
void saltTheEarth(){
if(spinMe){
digitalWrite(fan,HIGH);
}
else{
digitalWrite(fan,LOW);
}
delay(1000);
}
void getInput(){
if(digitalRead(inputLed) == HIGH && opened == false){
openBlock();
}
else if(digitalRead(inputLed) == LOW && opened == true){
digitalWrite(fan,LOW);
closeBlock();
}
}
void openBlock(){
for (posBlock = 0; posBlock <= 20; posBlock += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
theBlock.write(posBlock); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(1000);
opened = true;
spinMe = true;
}
void closeBlock(){
spinMe = false;
for (posBlock = 20; posBlock >= 0; posBlock -= 1) { // goes from 180 degrees to 0 degrees
theBlock.write(posBlock); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
delay(1000);
opened = false;
}