-
Notifications
You must be signed in to change notification settings - Fork 0
/
deviceCodeNew_sampleOverTime.ino
70 lines (66 loc) · 1.42 KB
/
deviceCodeNew_sampleOverTime.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
int rainSensor = A4;
int ledMOSFET = 3;
int motorMOSFET = 5;
int relayControl = 2;
void setup() {
Serial.begin(9600);
pinMode(rainSensor,INPUT);
pinMode(ledMOSFET,OUTPUT);
pinMode(motorMOSFET,OUTPUT);
pinMode(relayControl,OUTPUT);
}
int countDrops(){
int count = 0;
int rainReading;
float voltage;
for (int ii = 0; ii < 10; ii++){
rainReading = analogRead(rainSensor);
voltage = rainReading/1024.0 * 5.0;
if (voltage < 4.78) {
count++;
}
delay(100);
}
return count;
}
// wipeSetting: OFF = 0; LOW = 1; HIGH = 2
void motorControl(int wipeSetting){
switch (wipeSetting){
case 0:
analogWrite(motorMOSFET,0);
break;
case 1:
analogWrite(motorMOSFET,190);
digitalWrite(relayControl,LOW);
delay(4500);
digitalWrite(relayControl,HIGH);
delay(4400);
motorControl(0);
break;
case 2:
analogWrite(motorMOSFET,255);
digitalWrite(relayControl,LOW);
delay(1500);
digitalWrite(relayControl,HIGH);
delay(1400);
motorControl(0);
break;
}
}
void loop() {
// OFF (0 drops per second)
if (countDrops() == 0){
analogWrite(ledMOSFET,0);
motorControl(0);
}
// LOW intensity (< 5 drops per second)
else if (countDrops() < 5){
analogWrite(ledMOSFET,10);
motorControl(1);
}
// HIGH intensity (>= 5 drops per second)
else {
analogWrite(ledMOSFET,50);
motorControl(2);
}
}