Skip to content

Instantly share code, notes, and snippets.

@kwalseth
Created June 15, 2020 19:41
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 kwalseth/44de8099572d4ede21ef3b9f0295ec10 to your computer and use it in GitHub Desktop.
Save kwalseth/44de8099572d4ede21ef3b9f0295ec10 to your computer and use it in GitHub Desktop.
import time
import board
from adafruit_pyportal import PyPortal
from adafruit_button import Button
import neopixel
import analogio
# Set the background color
BACKGROUND_COLOR = 0x443355
# Set the NeoPixel brightness
BRIGHTNESS = 0.3
light_sensor = analogio.AnalogIn(board.LIGHT)
pixels = neopixel.NeoPixel(board.D4, 91, brightness=BRIGHTNESS)
# Turn off NeoPixels to start
pixels.fill(0)
# Setup PyPortal without networking
pyportal = PyPortal(default_bg=BACKGROUND_COLOR)
def fireeffect():
pixels[0:44] = [0xFF0000] * 44
pixels[83:91] = [0xFF0000] * 8
pixels[44:83] = [0x850000] * 39
pixels.show()
time.sleep(.2)
pixels[44:83] = [0xFF0000] * 39
pixels[0:44] = [0x850000] * 44
pixels[83:91] = [0x850000] * 8
pixels.show()
time.sleep(.2)
pixels[0:44] = [0xFF0000] * 44
pixels[83:91] = [0xFF0000] * 8
pixels[44:83] = [0x850000] * 39
pixels.show()
time.sleep(.2)
pixels[44:83] = [0xFF0000] * 39
pixels[0:44] = [0x850000] * 44
pixels[83:91] = [0x850000] * 8
pixels.show()
time.sleep(.2)
pixels[0:44] = [0xFF0000] * 44
pixels[83:91] = [0xFF0000] * 8
pixels[44:83] = [0x850000] * 39
pixels.show()
time.sleep(.2)
pixels[44:83] = [0xFF0000] * 39
pixels[0:44] = [0x850000] * 44
pixels[83:91] = [0x850000] * 8
pixels.show()
time.sleep(.2)
pixels.fill(RED)
pixels.show()
time.sleep(.1)
pixels.fill(ORANGE)
pixels.show()
time.sleep(.1)
pixels.fill(RED)
pixels.show()
time.sleep(.1)
pixels.fill(ORANGE)
pixels.show()
time.sleep(.1)
pixels.fill(RED)
pixels.show()
time.sleep(.1)
pixels.fill(ORANGE)
pixels.show()
time.sleep(.1)
mode = 1
# Button colors
RED = (255, 0, 0)
ORANGE = (155, 10, 0)
YELLOW = (255, 170, 0)
GREEN = (0, 255, 0)
CYAN = (0, 255, 255)
BLUE = (0, 0, 255)
VIOLET = (153, 0, 255)
MAGENTA = (0, 0, 0)
PINK = (255, 51, 119)
AQUA = (85, 125, 255)
WHITE = (255, 255, 255)
Fire = (0, 0, 0)
spots = [
{'label': "1", 'pos': (10, 10), 'size': (60, 60), 'color': RED},
{'label': "2", 'pos': (90, 10), 'size': (60, 60), 'color': ORANGE},
{'label': "3", 'pos': (170, 10), 'size': (60, 60), 'color': YELLOW},
{'label': "4", 'pos': (250, 10), 'size': (60, 60), 'color': GREEN},
{'label': "5", 'pos': (10, 90), 'size': (60, 60), 'color': CYAN},
{'label': "6", 'pos': (90, 90), 'size': (60, 60), 'color': BLUE},
{'label': "7", 'pos': (170, 90), 'size': (60, 60), 'color': VIOLET},
{'label': "8", 'pos': (250, 90), 'size': (60, 60), 'color': MAGENTA},
{'label': "9", 'pos': (10, 170), 'size': (60, 60), 'color': PINK},
{'label': "10", 'pos': (90, 170), 'size': (60, 60), 'color': AQUA},
{'label': "11", 'pos': (170, 170), 'size': (60, 60), 'color': WHITE},
{'label': "12", 'pos': (250, 170), 'size': (60, 60), 'color': Fire}
]
buttons = []
for spot in spots:
button = Button(x=spot['pos'][0], y=spot['pos'][1],
width=spot['size'][0], height=spot['size'][1],
style=Button.SHADOWROUNDRECT,
fill_color=spot['color'], outline_color=0x222222,
name=spot['label'])
pyportal.splash.append(button.group)
buttons.append(button)
mode = 0
while True:
touch = pyportal.touchscreen.touch_point
if touch:
for button in buttons:
if button.contains(touch):
print("Touched", button.name)
pixels.fill(button.fill_color)
if button.name == "12":
fireeffect()
time.sleep(0.15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment