import time, random
import board
from digitalio import DigitalInOut, Pull
from rainbowio import colorwheel
import neopixel
import busio
from lcd import LCD
from i2c_pcf8574_interface import I2CPCF8574Interface
from lcd import CursorMode
#init lcd
i2c = busio.I2C(board.GP3, board.GP2)
lcd = LCD(I2CPCF8574Interface(i2c, 0x27), num_rows=2, num_cols=16)
num_leds = 2
pixels = neopixel.NeoPixel(board.GP28, num_leds, brightness=1.0, auto_write=False, pixel_order=(1, 0, 2, 3))
button = DigitalInOut(board.GP0) # defaults to input
button.pull = Pull.UP # turn on internal pull-up resistor
text_list = ["Text1", "Text2", "Text3", "Text4", "Text5"]
color_configs = [[
(255, 0, 0, 0),
(255, 0, 0, 0)
],
[
(0, 0, 255, 0),
(255, 255, 255, 0)
],
[
(255, 255, 255, 0),
(0, 0, 255, 0)
],
[
(0, 255, 0, 0),
(255, 0, 0, 0)
],
[
(0, 0, 0, 255),
(0, 0, 0, 255)
]
]
def cycle_colors(config_index):
pixels.fill((0, 0, 0, 0))
for i, color in enumerate(color_configs[config_index-1]):
color_as_list = list(color)
print(color_as_list)
pixels[i] = color_as_list
lcd.clear()
lcd.print(text_list[config_index-1]) # change text what you want
pixels.show()
def turn_off_leds():
pixels.fill((0, 0, 0, 0))
pixels.show()
lcd.clear()
pressed_time = 0
config_index = 0
while True:
if not button.value:
if pressed_time == 0:
pressed_time = time.monotonic()
if time.monotonic() - pressed_time >= 3:
turn_off_leds()
config_index = 0
pressed_time = 1
elif time.monotonic() - pressed_time < 0.1:
config_index += 1
if config_index == len(color_configs):
turn_off_leds()
config_index = 0
cycle_colors(config_index)
time.sleep(0.2)
else:
pressed_time = 0
time.sleep(0.1) # A