Skip to content

Instantly share code, notes, and snippets.

@hashrock

hashrock/pomodoro.py

Created May 14, 2019
Embed
What would you like to do?
My first pomodoro app for M5Stack
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
You can’t perform that action at this time.