from ring import RED, BLUE, GREEN, BLACK, COLOURS, Ring
from debounced_switch import DebouncedSwitch
from machine import Pin, Timer
import callbacks_simple
from screen import Screen
import time
import random
r = Ring(11, brightness = .2)
screen = Screen(1, 2, 3)
textTop = 16
textLeft = 4
def splash(callback):
global textTop, textLeft
screen.reset(show=False)
screen.device.text('LED controller', textLeft, textTop)
screen.device.text('- v0.0.1a', textLeft, textTop * 2)
wrapper(show=False)
screen.device.show()
tim = Timer()
tim.init(mode=Timer.ONE_SHOT, callback=callback, period=1000)
def wrapperOnly(show = True):
screen.reset(show=False)
wrapper(show)
def wrapper(show = True):
screen.device.rect(0, 12, 120, 32, 1)
if (show):
screen.device.show()
def leftButton(ring):
global textTop, textLeft
wrapperOnly(show = False)
screen.device.text('Rainbow', textLeft, textTop)
screen.device.text('...', textLeft, textTop * 2)
screen.device.show()
callbacks_simple.rainbowToggle(ring)
screen.reset()
def rightButton(ring):
global textTop, textLeft
wrapperOnly(show = False)
percentage = random.randint(0, 100);
screen.device.text('{}%'.format(percentage), textLeft, textTop)
screen.device.text('...', textLeft, textTop * 2)
screen.device.show()
callbacks_simple.pro(ring, percentage)
# tim = Timer()
# tim.init(mode=Timer.ONE_SHOT, callback=wrapperOnly, period=1000)
def setup(_):
wrapperOnly()
DebouncedSwitch(Pin(13, Pin.IN, Pin.PULL_UP), leftButton, r)
DebouncedSwitch(Pin(14, Pin.IN, Pin.PULL_UP), rightButton, r)
splash(setup)