Last active
June 12, 2018 08:28
-
-
Save jon1012/6ca43eb05c4dfe7093c3f134abde3ebb to your computer and use it in GitHub Desktop.
Child day/night monitor M5Stack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This file is executed on every boot (including wake-boot from deepsleep) | |
import sys | |
sys.path[1] = '/flash/lib' | |
from m5stack import lcd, speaker, buttonA, buttonB, buttonC | |
# ---------- M5Cloud ------------ | |
if True: | |
if buttonB.isPressed(): | |
lcd.println('On: OFF-LINE Mode', color=lcd.ORANGE) | |
else: | |
import wifisetup | |
if buttonA.isPressed(): | |
lcd.println('On: SAFE moode, no main.py', color=lcd.ORANGE) | |
else: | |
import main | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"wifi": {"ssid": "votre-reseau", "password": "motdepasse"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from m5stack import machine | |
from m5stack import lcd | |
from time import strftime | |
import utime | |
# initializer le RTC | |
rtc = machine.RTC() | |
print("Synchronize time from NTP server with TZ=France ...") | |
rtc.ntp_sync(server="hr.pool.ntp.org", tz="CET-1CEST,M3.5.0,M10.5.0/3") | |
def watch(): | |
# on boucle... | |
while True: | |
if 7 <= utime.localtime()[3] < 21: | |
lcd.image(0,0,"awake0.jpg") | |
else: | |
lcd.image(0,0,"night0.jpg") | |
# si l'horloge n'est pas synchro... on affiche l'heure en rouge, sinon en vert. | |
if not rtc.synced(): # set color to sync status | |
lcd.setColor(lcd.RED) | |
else: | |
lcd.setColor(lcd.GREEN) | |
lcd.setCursor(243, 227) | |
lcd.print("{}".format(utime.strftime('%H:%M:%S', utime.localtime())), lcd.RIGHT, lcd.BOTTOM, transparent=True) | |
utime.sleep(1) | |
watch() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment