diff options
Diffstat (limited to 'Arduino/ardu/ardu.ino')
-rw-r--r-- | Arduino/ardu/ardu.ino | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/Arduino/ardu/ardu.ino b/Arduino/ardu/ardu.ino new file mode 100644 index 0000000..65e6f52 --- /dev/null +++ b/Arduino/ardu/ardu.ino @@ -0,0 +1,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); +} |