1#include <Servo.h>
2#include <NewPing.h>
3
4#define TRIGGER_PIN 7
5#define ECHO_PIN 7
6#define MAX_DISTANCE 200
7
8NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
9
10Servo drop;
11Servo lift;
12int state = 0;
13
14int storeCM = 0;
15
16
17int tripdistance = 40;
18int lifttime = 16000;
19
20
21void setup() {
22 Serial.begin(115200);
23 drop.attach(9);
24 lift.attach(10);
25 drop.write(150);
26 delay(1000);
27 drop.write(80);
28 lift.write(180);
29 delay(lifttime);
30 lift.write(90);
31
32}
33
34void loop() {
35 Serial.print("Distance: ");
36 Serial.println(sonar.ping_cm());
37 storeCM=sonar.ping_cm();
38
39 if(storeCM <= tripdistance && storeCM > 3 && state == 1) {
40 Serial.println("DROP THE SPIDER!");
41 drop.write(150);
42 delay(5000);
43 drop.write(80);
44 lift.write(180);
45 delay(lifttime);
46 lift.write(90);
47 delay(1000);
48 delay(100);
49 state = 0;
50 }
51
52 if(storeCM > tripdistance && state == 0) {
53 state = 1;
54 }
55
56}