Skip to content

Commit fc3497a

Browse files
authored
Add interactive functionality (#6)
1 parent 49e4e02 commit fc3497a

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# patrIoT
22

3-
Daily AI generated patriotic images on the Adafruit MagTag
3+
Daily AI generated patriotic images on the AdaFruit MagTag
44

55
![Demo Image](demo.png)
66

77
## Client Requirements
88

9-
Use the included boot.py to remount the internal storage as read/write after boot.
10-
Hold down the A / left-most face button (D15) to disable this and instead allow your PC write to the circuitpy drive over USB.
9+
Use the included `boot.py` to remount the internal storage as read/write after boot.
10+
Hold down the left-most face button (D15) to disable this and instead allow your PC write to the CircuitPy drive over USB.
1111

1212
MagTag code is written in CircuitPython. The following libraries are required:
1313

@@ -25,6 +25,6 @@ See `server/requirements.txt`
2525

2626
## Usage
2727

28-
The server-side code runs as a systemd timer once every 24 hours. It generates a new patriotic image via the OpenAI DALL-E-3 API.
28+
The server-side code runs as a `systemd` timer once every 24 hours. It generates a new patriotic image via the OpenAI image generation API.
2929

30-
The MagTag reaches out to the server every 24 hours to get the latest image and display it.
30+
Pressing the right-most face button (D11) on the MagTag will trigger red, white, and blue LEDs, play the star spangled banner, and display the most recent image.

magtag/code.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,37 @@
88
import storage
99
import board
1010
import random
11+
import alarm
12+
import digitalio
1113

1214
magtag = MagTag()
1315

16+
magtag.peripherals.buttons[3].deinit()
17+
pin_alarm = alarm.pin.PinAlarm(pin=board.D11, value=False, pull=True)
18+
19+
note_1 = 233
20+
note_2 = 294
21+
note_3 = 330
22+
note_4 = 349
23+
note_5 = 392
24+
note_6 = 440
25+
note_7 = 466
26+
note_8 = 523
27+
note_9 = 587
28+
note_10 = 622
29+
note_11 = 698
30+
31+
try:
32+
# Set NeoPixel colors using MagTag's built-in NeoPixel management
33+
magtag.peripherals.neopixel_disable = False
34+
magtag.peripherals.neopixels[3] = (255, 255, 255) # Bright white
35+
magtag.peripherals.neopixels[0] = (255, 255, 255) # Bright white
36+
magtag.peripherals.neopixels[2] = (255, 0, 0) # Bright red
37+
magtag.peripherals.neopixels[1] = (0, 0, 255) # Bright blue
38+
magtag.peripherals.neopixels.show()
39+
except:
40+
pass
41+
1442
if storage.getmount('/').readonly:
1543
magtag.add_text(
1644
text_position=(
@@ -41,8 +69,6 @@
4169
else:
4270
print("Failed to download the image")
4371
except:
44-
# we might be offline
45-
sleeptime = 120
4672
pass
4773

4874
try:
@@ -91,8 +117,14 @@
91117
while board.DISPLAY.busy:
92118
pass
93119
except:
94-
sleeptime=120
95120
pass
96121

97-
# go into sleep mode until we rotate the image or get online again
98-
magtag.exit_and_deep_sleep(sleeptime)
122+
try:
123+
magtag.peripherals.neopixels.fill((0, 0, 0)) # Turn off all NeoPixels
124+
magtag.peripherals.neopixels.show()
125+
magtag.peripherals.neopixel_disable = True
126+
except:
127+
pass
128+
129+
# go into sleep mode until we press D11 again
130+
alarm.exit_and_deep_sleep_until_alarms(pin_alarm)

0 commit comments

Comments
 (0)