-
Notifications
You must be signed in to change notification settings - Fork 0
/
verstuiver.ino
59 lines (44 loc) · 1.63 KB
/
verstuiver.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
// WaterVerstuiver aka Squirtalyzer by Pidgey.be
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 60; // variable to store the servo position
long interval= 10000; //squirt every 10sec
unsigned long lastSpuit=0;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(7, INPUT_PULLUP); //use a switch that connects pin 7 to ground to activate the squirter
pinMode(A0, INPUT);
//beginpositie
myservo.write(pos);
//voor debug:
//Serial.begin(9600);
}
void loop()
{
if(digitalRead(7)==LOW)
{
myservo.write(180);
delay(1000);
myservo.write(pos);
delay(1000); //wait
}
else
{
interval = map(analogRead(0),0,700,10000,1200000); //potentiometer is connected to 3.3V, so analogread goes max to 700 (ipv 1023).
// 10000 = 10 seconds min interval
// 1200000 = 20min max interval
//Serial.println(analogRead(0));
//Serial.println(interval);
if(millis()>(lastSpuit+interval)) spuit();
}
}
void spuit()
{
myservo.write(180);
delay(800); // waits 800ms for the servo to reach the position
myservo.write(pos);
delay(500);
lastSpuit = millis();
}