diff options
| author | Carlos Maiolino <[email protected]> | 2025-09-06 09:26:21 +0200 |
|---|---|---|
| committer | Carlos Maiolino <[email protected]> | 2025-09-06 09:26:21 +0200 |
| commit | 973e27b243ea7f12b6743894465c67a4a6a87eb2 (patch) | |
| tree | 006a2d9fc8f86b4914499302325fbcaa3941e17c /C/HF/chap4/lab1 | |
| parent | 736967952470e740781c95cf5afb7e705ec59030 (diff) | |
Move some other code here
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'C/HF/chap4/lab1')
| -rw-r--r-- | C/HF/chap4/lab1/moisture.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/C/HF/chap4/lab1/moisture.c b/C/HF/chap4/lab1/moisture.c new file mode 100644 index 0000000..349050f --- /dev/null +++ b/C/HF/chap4/lab1/moisture.c @@ -0,0 +1,45 @@ +/* This works - tested on Tinkercad */ +#define THRESHOLD 800 +#define DRY 500 + +#define LED 13 + +setup(){ + Serial.begin(9600); + pinMode(LED, OUTPUT); + digitalWrite(LED, LOW); +} + +void blink_led(long interval) { + digitalWrite(LED, LOW); + delay(interval); + digitalWrite(LED, HIGH); +} + +void led_on(void) +{ + if (digitalRead(LED) == LOW) + digitalWrite(LED, HIGH); +} + +void led_off(void) +{ + if (digitalRead(LED) == HIGH) { + digitalWrite(LED, LOW); + Serial.println("Thank you, Seymour"); + } +} + +void loop(){ + int moist = analogRead(1); + if (moist > THRESHOLD) { + led_off(); + continue; + } + + if (moist < DRY) + blink_led(500); + else + led_on(); + Serial.println("Feed me!"); +} |
