Skip to content

Instantly share code, notes, and snippets.

@andywarburton
Last active August 29, 2023 11:32
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 andywarburton/69482575b82fdb1de4c51bdc0a367a89 to your computer and use it in GitHub Desktop.
Save andywarburton/69482575b82fdb1de4c51bdc0a367a89 to your computer and use it in GitHub Desktop.
PyModoro a CircuitPython Pomodoro Productivity Timer
import time
import board
from digitalio import DigitalInOut, Direction, Pull
import neopixel
# configure your timer
work_minutes = 20
rest_minutes = 5
# define colours
work_color = (0,10,255)
rest_color = (0,255,10)
off_color = (0,0,0)
switch = DigitalInOut(board.D1)
switch.direction = Direction.INPUT
switch.pull = Pull.UP
# setup onboard neopixel
led = neopixel.NeoPixel(board.NEOPIXEL, 1)
led.brightness = 0.8
# setup neopixel ring
num_pixels =24
ring = neopixel.NeoPixel(board.A3, num_pixels, auto_write=False)
ring.brightness = 0.2
# lazy math
work_delay = round((work_minutes*60)/num_pixels,0)
rest_delay = round((rest_minutes*60)/num_pixels,0)
start_timer = False
while True:
if(start_timer == True):
# loop for work time
for i in range(num_pixels):
ring[i] = work_color
ring.show()
time.sleep(work_delay)
# reset the ring
for i in range(num_pixels):
ring[i] = off_color
ring.show()
# loop for rest time
for i in range(num_pixels):
ring[i] = rest_color
ring.show()
time.sleep(work_delay)
else:
# reset the ring
for i in range(num_pixels):
ring[i] = off_color
ring.show()
if switch.value:
# button not pressed
led[0] = (255, 0, 0)
start_timer = False
else:
# button pressed
led[0] = (0, 255, 0)
start_timer = True
time.sleep(0.01) # debounce delay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment