Skip to content

Instantly share code, notes, and snippets.

@hexagit
Last active June 12, 2019 05:28
Show Gist options
  • Save hexagit/48c095041b92d771569d8254a64212ea to your computer and use it in GitHub Desktop.
Save hexagit/48c095041b92d771569d8254a64212ea to your computer and use it in GitHub Desktop.
m5stackで植物を育てる
from m5stack import lcd
from m5stack import *
import utime
lcd.clear()
lcd.setCursor(0, 0)
lcd.setColor(lcd.WHITE)
#画像データ名
imgs=["desert","flower_1","flower_2","flower_3","flower_4"]
value=0
count=0
growthStep=0
fw, fh = lcd.fontSize()
sw, sh = lcd.screensize()
#湿度を36番ピンから取得
adc = machine.ADC(36)
#画像セット
def setImage(num):
lcd.clear()
lcd.image(lcd.CENTER, lcd.CENTER, file=imgs[num]+".jpeg", scale=0, type=lcd.JPG)
#初期画像セット
setImage(0)
while True:
earlierStep=growthStep
value=adc.read()
#ボタン押したら処理中断
if buttonA.wasPressed():
break
#値が300を超えたら砂漠化
if value>300:
growthStep=0
count=0
else:
count+=1
if count>0 and count<10:
growthStep=1
elif count>=10 and count<20:
growthStep=2
elif count>=20 and count<30:
growthStep=3
elif count>=30:
growthStep=4
if earlierStep!= growthStep:
setImage(growthStep)
  
lcd.text(lcd.CENTER,lcd.BOTTOM,str(value))
time.sleep(1)
#湿度表示部分をクリア
lcd.setwin(0, (sh - fh) - 1, sw - 1, sh - 1)
lcd.clearwin()
lcd.resetwin()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment