code.py
1 # SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries 2 # 3 # SPDX-License-Identifier: MIT 4 5 import time 6 from adafruit_circuitplayground.express import cpx 7 import touchio 8 import simpleio 9 import board 10 11 cpx.pixels.brightness = 0.2 12 touch = touchio.TouchIn(board.A1) 13 14 DRY_VALUE = 1500 # calibrate this by hand! 15 WET_VALUE = 2100 # calibrate this by hand! 16 17 while True: 18 value_A1 = touch.raw_value 19 print((value_A1,)) 20 21 # fill the pixels from red to green based on soil moisture 22 percent_wet = int(simpleio.map_range(value_A1, DRY_VALUE, WET_VALUE, 0, 100)) 23 cpx.pixels.fill((100-percent_wet, percent_wet, 0)) 24 time.sleep(0.5)