Last active
March 26, 2019 20:34
-
-
Save yeyeto2788/2619f3f9d9cf739464b0ae47ec6217ed to your computer and use it in GitHub Desktop.
Quick Pomodoro Technique wirtten in MicroPython
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
import machine | |
import neopixel | |
import time | |
import urandom | |
pixel_count = 12 | |
neostrip = neopixel.NeoPixel(machine.Pin(12), 12) | |
button13 = machine.Pin(13, machine.Pin.IN) | |
button14 = machine.Pin(14, machine.Pin.IN) | |
button02 = machine.Pin(2, machine.Pin.IN) | |
button00 = machine.Pin(0, machine.Pin.IN) | |
colors = {"red":[60, 0, 0], "green":[0, 60, 0], "blue":[0, 0, 60], | |
"yellow":[60, 60, 0], "white":[60, 60, 60], | |
"nocolor":[0, 0, 0]} | |
def lapse_time(pintMins, pstrColor, pstrmsg=''): | |
totalMins = pintMins - 1 | |
for Mins in range(totalMins, -1, -1): | |
for Secs in range(60, 0, -1): | |
Data = '{:02d} : {:02d}'.format(Mins, Secs) | |
print("Remaining time:", Data) | |
for milisecs in range(40, 0, -1): | |
set_pixel_color(milisecs % 12, pstrColor) | |
time.sleep_ms(25) | |
def get_random_int(): | |
int_return = urandom.getrandbits(8) | |
if int_return < 256: | |
return int_return | |
else: | |
return 0 | |
def set_pixel_color(intNeopixel, pstrColor): | |
if neostrip[intNeopixel] != (0, 0, 0): | |
neostrip[intNeopixel] = (0, 0, 0) | |
else: | |
if pstrColor in colors: | |
neostrip[intNeopixel] = colors[pstrColor] | |
neostrip.write() | |
def slow_fill_color(pstrColor): | |
for i in range(0, pixel_count): | |
neostrip[i] = colors[pstrColor] | |
time.sleep_ms(25) | |
neostrip.write() | |
def color_neostrip(neostrip, pstrColor, pintPixelCount): | |
if pstrColor in colors: | |
for intcounter in range(pintPixelCount): | |
neostrip[intcounter] = colors[pstrColor] | |
neostrip.write() | |
while True: | |
if (button13.value() == 0): | |
lapse_time(25, "red", "POMODORO") | |
lapse_time(5, "green", "FREE TIME") | |
elif (button14.value() == 0): | |
for color in colors: | |
color_neostrip(neostrip, color, pixel_count) | |
time.sleep(0.5) | |
color_neostrip(neostrip, 'nocolor', pixel_count) | |
elif (button02.value() == 0): | |
for color in colors: | |
slow_fill_color(color) | |
time.sleep_ms(100) | |
color_neostrip(neostrip, 'nocolor', pixel_count) | |
elif (button00.value() == 0): | |
for i in range(0, pixel_count): | |
color = [get_random_int(), get_random_int(), get_random_int()] | |
print(color) | |
neostrip[i] = color | |
time.sleep_ms(25) | |
neostrip.write() | |
time.sleep_ms(100) | |
color_neostrip(neostrip, 'nocolor', pixel_count) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment