-
Notifications
You must be signed in to change notification settings - Fork 0
/
watercanon.ino
56 lines (48 loc) · 938 Bytes
/
watercanon.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
#include <Servo.h>
int analogIn = A0;
int digitalIn = D1;
int ledOne = D2;
int servoStop = 96;
Servo waterCanon;
void setup ()
{
pinMode (analogIn, INPUT);
pinMode (digitalIn, INPUT);
pinMode (ledOne, OUTPUT);
waterCanon.attach(D3);
Serial.begin (9600);
}
void loop ()
{
float analogValue;
int digitalValue;
int i = 0;
bool t = false;
digitalWrite (ledOne, LOW);
waterCanon.write(servoStop);
while (i < 100)
{
digitalValue = digitalRead (digitalIn);
if (digitalValue==1)
{
Serial.println ("We are live");
t = true;
break;
}
i++;
}
if (t)
{
Serial.println ("Set of water 'canon'");
digitalWrite (ledOne, HIGH);
// Full speed ahead for 0,5 seconds
waterCanon.write(0);
delay(500);
// Hoooold..!
waterCanon.write(servoStop);
delay(2000);
// Backup
waterCanon.write(180);
delay(500);
}
}