Created
May 14, 2019 16:52
-
-
Save hashrock/72924aaad2ee1dd0d9befea5899ae12c to your computer and use it in GitHub Desktop.
My first pomodoro app for M5Stack
This file contains hidden or 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 * | |
import utime | |
import math | |
cnt = 0 | |
m_cnt = cnt | |
start = False | |
done = False | |
def init(): | |
global cnt | |
global m_cnt | |
global done | |
global start | |
done = False | |
start = False | |
lcd.clear(lcd.BLACK) | |
cnt = 10 * 60 * 25 | |
m_cnt = cnt | |
lcd.setCursor(0, 0) | |
lcd.setColor(lcd.RED) | |
lcd.font(2) | |
lcd.println("Pomodoro v0.0.1") | |
def redraw(cnt): | |
global m_cnt | |
lcd.setCursor(lcd.CENTER, 100) | |
lcd.setColor(lcd.WHITE) | |
if start : | |
lcd.setColor(lcd.GREEN) | |
lcd.textClear(lcd.CENTER, 100, "xx:xx") | |
minute = '%02d' % math.floor(cnt / 60) | |
second = '%02d' % (cnt % 60) | |
lcd.println("{0}:{1}".format(minute, second)) | |
# Graph | |
lcd.roundrect(10, 130, 300, 10, 4, lcd.WHITE, lcd.BLACK) | |
lcd.roundrect(10, 130, round(300 * ( 1 - cnt * 10 / m_cnt)), 10, 1, lcd.WHITE, lcd.WHITE) | |
init() | |
redraw(math.floor(cnt / 10)) | |
while True: | |
utime.sleep(0.1) | |
if buttonA.wasReleased(): | |
start = True | |
redraw(math.floor(cnt / 10)) | |
if buttonC.wasReleased(): | |
init() | |
redraw(math.floor(cnt / 10)) | |
if done : | |
continue | |
if start : | |
cnt -= 1 | |
if cnt <= 0 : | |
lcd.setCursor(0, 0) | |
lcd.clear(lcd.BLUE) | |
lcd.setColor(lcd.RED) | |
lcd.font(2) | |
lcd.print("Finish!") | |
done = True | |
if not start : | |
continue | |
if cnt % 10 == 0 : | |
redraw(math.floor(cnt / 10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment