-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchipmunkBeGone.ino
81 lines (70 loc) · 1.59 KB
/
chipmunkBeGone.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
// DESIGNED AND BUILT BY DENNIS ROTNOV
// Feel free to use it and change, but please keep authorship attribution
#include <Servo.h>
#define LEYE 8 // Left eye LED
#define REYE 7 // Right eye LED
#define PSERVO 6 // Cuts power to servo to save power
#define SERVO 10
#define PIR 0 // Motion sensor
#define OWL 1 // Audio
Servo Myservo;
int pos = 0;
long now = 0;
long last = 0;
const int period = 200;
void chipmonkBeGone();
void blink();
void move();
void setup() {
pinMode(PIR, INPUT);
pinMode(LEYE, OUTPUT);
pinMode(OWL, OUTPUT);
pinMode(REYE, OUTPUT);
pinMode(PSERVO, OUTPUT);
digitalWrite(LEYE, 0);
digitalWrite(REYE, 0);
digitalWrite(PSERVO, 0);
digitalWrite(OWL, 1);
Myservo.attach(SERVO);
}
void loop() {
// Used nested delays to decrease false alarms
if (digitalRead(PIR) == 1) {
delay(300);
if (digitalRead(PIR) == 1){
digitalWrite(OWL, 0);
chipmonkBeGone();
delay(7000);
digitalWrite(OWL, 1);
}
}
}
void chipmonkBeGone() {
move();
blink();
}
// Controls LEDs in owl's eyes
void blink() {
for (int i=0; i<10; i++) {
digitalWrite(REYE, 1);
digitalWrite(LEYE, 1);
delay(50);
digitalWrite(REYE, 0);
digitalWrite(LEYE, 0);
delay(50);
}
}
// Activates servos
void move() {
digitalWrite(PSERVO, 1);
for (pos = 0; pos <= 80; pos+=2) {
Myservo.write(pos);
delay(15);
}
for (pos = 80; pos >= 0; pos-=2
) {
Myservo.write(pos);
delay(15);
}
digitalWrite(PSERVO, 0);
}