Skip to content

Instantly share code, notes, and snippets.

@benfoxall
Created April 5, 2021 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benfoxall/9ae1e64cc8298816c3db5571198ce4aa to your computer and use it in GitHub Desktop.
Save benfoxall/9ae1e64cc8298816c3db5571198ce4aa to your computer and use it in GitHub Desktop.
## Hacky pomodoro script for pi pico
from math import floor
import picounicorn
from machine import Pin, Timer
picounicorn.init()
w = picounicorn.get_width()
h = picounicorn.get_height()
total = w * h
count = 0
state = "idle"
def fill(r, g, b):
for x in range(w):
for y in range(h):
picounicorn.set_pixel(x, y, r, g, b)
def loop(timer):
global count
global state
if state == "active":
if count < total:
x = count % w
y = floor(count / w)
picounicorn.set_pixel(x, y, 100, 0, 0)
count = count + 1
else:
state = "break"
fill(0,100,0)
if state == "break":
if count > 0:
count = count - 1
x = count % w
y = floor(count / w)
picounicorn.set_pixel(x, y, 0, 0, 0)
else
state = "idle"
loopTimer = Timer()
loopTimer.init(freq=40.0, mode=Timer.PERIODIC, callback=loop)
def button(timer):
global count
global state
if picounicorn.is_pressed(picounicorn.BUTTON_A) and state != "active":
print("START")
count = 0
state = "active"
fill(0,0,0)
if picounicorn.is_pressed(picounicorn.BUTTON_B) and state != "idle":
print("RESET")
state = "idle"
fill(0,0,0)
ButtonTimer = Timer()
ButtonTimer.init(freq=50.0, mode=Timer.PERIODIC, callback=button)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment