blob: 65e6f527b6697b84d7c0d5d17e7d0c6ca9450bba (
plain)
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
|
#include <Servo.h>
int relayInput = 27; int moistSensor = A10; Servo servo1; Servo servo2;
enum Material {
dry = 0, wet = 1, metal = 2, none = 4,
};
enum Material material = dry; int timer = -1; int wetTick = 0; int
wetTickThreshold = 7; void setup() {
pinMode(relayInput, INPUT); digitalWrite(relayInput, HIGH);
pinMode(moistSensor, INPUT); servo1.attach(8); servo2.attach(9);
servo1.write(180); servo2.write(90); Serial.begin(9600);
}
void loop() { int metalState = digitalRead(relayInput); int moistState =
analogRead(moistSensor); if (timer >= 0) {
timer--;
}
if (timer == -1) { if (metalState == LOW) { servo1.write(135);
servo2.write(90); material = metal; timer = 120;
} else {
servo1.write(180); if (moistState <= 800) { wetTick++; if (wetTick
>= wetTickThreshold) {
servo2.write(70); material = wet; timer = 100;
}
} else {
wetTick = 0; servo2.write(90); material = dry;
}
}
}
delay(100); Serial.print("Moisture: "); Serial.print(moistState);
Serial.print("; Metal: "); Serial.print(metalState); Serial.print(";
Material: "); Serial.print(material); Serial.print("; Timer: ");
Serial.print(timer); Serial.print("; wetTick: ");
Serial.println(wetTick);
}
|