# Plant moisture checker: a free micro:bit lesson from Maze Education
# https://maze.education/microbit/lessons/plant-moisture-checker
# MicroPython for the micro:bit Python Editor: https://python.microbit.org

# Plant moisture checker: leads clipped to pins P0 and P1, their metal pins in the soil. Hold A to see the reading.
from microbit import *

dry = 500
while True:
    pin1.write_digital(1)
    sleep(10)
    moisture = pin0.read_analog()
    pin1.write_digital(0)
    if button_a.is_pressed():
        display.scroll(moisture)
    elif moisture < dry:
        display.show(Image.SAD)
    else:
        display.show(Image.HAPPY)
    sleep(1000)
