Skip to content

Commit 071d755

Browse files
committed
Add Pixels output for event - FunHouse board
1 parent 0071dd5 commit 071d755

File tree

1 file changed

+33
-5
lines changed
  • CircuitPython_Day_2024_Projects/Feather_ReverseTFT_IO_Countdown

1 file changed

+33
-5
lines changed

CircuitPython_Day_2024_Projects/Feather_ReverseTFT_IO_Countdown/code.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
import microcontroller
1212
import adafruit_connection_manager
1313
import adafruit_requests
14+
15+
## Import either NeoPixel or DotStar, depending on your hardware
16+
# import neopixel
17+
from adafruit_dotstar import DotStar
18+
1419
from adafruit_io.adafruit_io import IO_HTTP
1520
from adafruit_bitmap_font import bitmap_font
1621
from adafruit_display_text import bitmap_label
@@ -22,28 +27,42 @@
2227
#timezone = None # Or instead rely on automatic timezone detection based on IP Address
2328

2429

25-
# The time of the thing!
30+
## The time of the thing!
2631
EVENT_YEAR = 2024
2732
EVENT_MONTH = 8
2833
EVENT_DAY = 16
2934
EVENT_HOUR = 0
3035
EVENT_MINUTE = 0
31-
# we'll make a python-friendly structure
36+
## we'll make a python-friendly structure
3237
event_time = time.struct_time((EVENT_YEAR, EVENT_MONTH, EVENT_DAY,
3338
EVENT_HOUR, EVENT_MINUTE, 0, # we don't track seconds
3439
-1, -1, False)) # we dont know day of week/year or DST
3540

3641
wifi.radio.connect(os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD"))
3742

38-
# Initialize a requests session using the newer connection manager
39-
# See https://adafruit-playground.com/u/justmobilize/pages/adafruit-connection-manager
43+
## Initialize a requests session using the newer connection manager
44+
## See https://adafruit-playground.com/u/justmobilize/pages/adafruit-connection-manager
4045
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
4146
ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
4247
requests = adafruit_requests.Session(pool, ssl_context)
4348

44-
# Create an instance of the Adafruit IO HTTP client
49+
## Create an instance of the Adafruit IO HTTP client
4550
io = IO_HTTP(os.getenv("ADAFRUIT_AIO_USERNAME"), os.getenv("ADAFRUIT_AIO_KEY"), requests)
4651

52+
## Setup RGB LEDs - comment out the DotStar import and setup if using NeoPixel
53+
pixels_length = 1 # Set to the number of pixels in your strip (funhouse has 5)
54+
pixels_brightness = 0.4 # Set to a value between 0.0 and 1.0
55+
# Uncomment the following lines if you are using DotStar and update pins if necessary
56+
dotstar_clock_pin = board.DOTSTAR_CLOCK
57+
dotstar_data_pin = board.DOTSTAR_DATA
58+
pixels = DotStar(dotstar_clock_pin, dotstar_data_pin, pixels_length, brightness=pixels_brightness)
59+
## Uncomment the following lines if you are using NeoPixel and update pin if necessary
60+
# neopixel_pin = board.NEOPIXEL
61+
# pixels = neopixel.NeoPixel(neopixel_pin, pixels_length, brightness=pixels_brightness)
62+
63+
pixels.fill((0, 0, 0)) # Turn off all pixels
64+
65+
# Setup built-in display
4766
display = board.DISPLAY
4867
group = displayio.Group()
4968
font = bitmap_font.load_font("/Helvetica-Bold-16.pcf")
@@ -95,6 +114,12 @@
95114
finished = True
96115
if not first_run and days_remaining == 0:
97116
scrolling_label.text = "It's CircuitPython Day 2024! The snakiest day of the year!"
117+
# Flash on/off blinka colours (nice purple) each second
118+
if pixels[0] == (0, 0, 0):
119+
pixels.fill((0x40, 0x00, 0x80))
120+
else:
121+
pixels.fill((0, 0, 0))
122+
98123
# Check for the moment of the event to trigger something (a NASA snake launch)
99124
if not triggered and (
100125
hours_remaining==0 and mins_remaining == 0 and secs_remaining <= 0
@@ -103,6 +128,8 @@
103128
print("Launch the snakes!")
104129
triggered = True
105130
io.send_data("cpday-countdown", "Launch the snakes!")
131+
else:
132+
pixels.fill((0, 0, 0)) # Turn off all pixels
106133
else:
107134
secs_remaining = remaining % 60
108135
remaining //= 60
@@ -111,6 +138,7 @@
111138
hours_remaining = remaining % 24
112139
remaining //= 24
113140
days_remaining = remaining
141+
pixels.fill((0, 0, 0)) # Turn off all pixels
114142
if not finished or (finished and days_remaining < 0):
115143
scrolling_label.text = (f"{days_remaining} DAYS, {hours_remaining} HOURS," +
116144
f"{mins_remaining} MINUTES & {secs_remaining} SECONDS")

0 commit comments

Comments
 (0)