|
11 | 11 | import microcontroller
|
12 | 12 | import adafruit_connection_manager
|
13 | 13 | import adafruit_requests
|
| 14 | + |
| 15 | +## Import either NeoPixel or DotStar, depending on your hardware |
| 16 | +# import neopixel |
| 17 | +from adafruit_dotstar import DotStar |
| 18 | + |
14 | 19 | from adafruit_io.adafruit_io import IO_HTTP
|
15 | 20 | from adafruit_bitmap_font import bitmap_font
|
16 | 21 | from adafruit_display_text import bitmap_label
|
|
22 | 27 | #timezone = None # Or instead rely on automatic timezone detection based on IP Address
|
23 | 28 |
|
24 | 29 |
|
25 |
| -# The time of the thing! |
| 30 | +## The time of the thing! |
26 | 31 | EVENT_YEAR = 2024
|
27 | 32 | EVENT_MONTH = 8
|
28 | 33 | EVENT_DAY = 16
|
29 | 34 | EVENT_HOUR = 0
|
30 | 35 | EVENT_MINUTE = 0
|
31 |
| -# we'll make a python-friendly structure |
| 36 | +## we'll make a python-friendly structure |
32 | 37 | event_time = time.struct_time((EVENT_YEAR, EVENT_MONTH, EVENT_DAY,
|
33 | 38 | EVENT_HOUR, EVENT_MINUTE, 0, # we don't track seconds
|
34 | 39 | -1, -1, False)) # we dont know day of week/year or DST
|
35 | 40 |
|
36 | 41 | wifi.radio.connect(os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD"))
|
37 | 42 |
|
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 |
40 | 45 | pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
|
41 | 46 | ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
|
42 | 47 | requests = adafruit_requests.Session(pool, ssl_context)
|
43 | 48 |
|
44 |
| -# Create an instance of the Adafruit IO HTTP client |
| 49 | +## Create an instance of the Adafruit IO HTTP client |
45 | 50 | io = IO_HTTP(os.getenv("ADAFRUIT_AIO_USERNAME"), os.getenv("ADAFRUIT_AIO_KEY"), requests)
|
46 | 51 |
|
| 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 |
47 | 66 | display = board.DISPLAY
|
48 | 67 | group = displayio.Group()
|
49 | 68 | font = bitmap_font.load_font("/Helvetica-Bold-16.pcf")
|
|
95 | 114 | finished = True
|
96 | 115 | if not first_run and days_remaining == 0:
|
97 | 116 | 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 | + |
98 | 123 | # Check for the moment of the event to trigger something (a NASA snake launch)
|
99 | 124 | if not triggered and (
|
100 | 125 | hours_remaining==0 and mins_remaining == 0 and secs_remaining <= 0
|
|
103 | 128 | print("Launch the snakes!")
|
104 | 129 | triggered = True
|
105 | 130 | io.send_data("cpday-countdown", "Launch the snakes!")
|
| 131 | + else: |
| 132 | + pixels.fill((0, 0, 0)) # Turn off all pixels |
106 | 133 | else:
|
107 | 134 | secs_remaining = remaining % 60
|
108 | 135 | remaining //= 60
|
|
111 | 138 | hours_remaining = remaining % 24
|
112 | 139 | remaining //= 24
|
113 | 140 | days_remaining = remaining
|
| 141 | + pixels.fill((0, 0, 0)) # Turn off all pixels |
114 | 142 | if not finished or (finished and days_remaining < 0):
|
115 | 143 | scrolling_label.text = (f"{days_remaining} DAYS, {hours_remaining} HOURS," +
|
116 | 144 | f"{mins_remaining} MINUTES & {secs_remaining} SECONDS")
|
|
0 commit comments