-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArduino-Spider-Dropper.ino
66 lines (50 loc) · 1.32 KB
/
Arduino-Spider-Dropper.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
/* 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 myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
const int pressurePlatePin = 2;
const int motorPin = 4;
int servoOpenPosition = 90; // variable to store the servo position
int servoClosedPosition = 0; // variable to store the servo position
int reelTime = 1000;
int hangTime = 5000;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(pressurePlatePin, INPUT);
digitalWrite(pressurePlatePin, HIGH);
pinMode(motorPin, OUTPUT);
myservo.write(servoClosedPosition); // tell servo to go to position in variable 'pos'
delay(500);
}
void loop() {
if(triggered()){
dropSpider();
delay(hangTime);
raiseSpider();
}
}
bool triggered(){
int buttonState = digitalRead(pressurePlatePin);
if(buttonState == LOW)
return true;
else
return false;
}
void dropSpider() {
myservo.write(servoOpenPosition);
}
void raiseSpider() {
runMotor();
myservo.write(servoClosedPosition);
}
void runMotor(){
digitalWrite(motorPin, HIGH);
delay(reelTime);
digitalWrite (motorPin, LOW);
}