|
1 | 1 | import time
|
2 |
| -import board |
3 |
| -from adafruit_magtag.magtag import MagTag |
4 | 2 | import displayio
|
5 |
| - |
6 |
| -display = board.DISPLAY |
| 3 | +import wifi |
| 4 | +import os |
| 5 | +from adafruit_magtag.magtag import MagTag |
| 6 | +import adafruit_requests |
| 7 | +import socketpool |
| 8 | +import ssl |
| 9 | +from adafruit_imageload import load |
| 10 | +from io import BytesIO |
7 | 11 |
|
8 | 12 | magtag = MagTag()
|
9 | 13 |
|
10 |
| -# Load the image |
11 |
| -bitmap = displayio.OnDiskBitmap("usa.bmp") |
| 14 | +# Connect to WiFi |
| 15 | +wifi.radio.connect(os.getenv("CIRCUITPY_WIFI_SSID"), os.getenv("CIRCUITPY_WIFI_PASSWORD")) |
| 16 | + |
| 17 | +# URL of the bitmap image |
| 18 | +url = "http://137.184.19.28:80/murica.bmp" |
| 19 | + |
| 20 | +# Download the image |
| 21 | +pool = socketpool.SocketPool(wifi.radio) |
| 22 | +requests = adafruit_requests.Session(pool, ssl.create_default_context()) |
| 23 | +response = requests.get(url) |
| 24 | +if response.status_code == 200: |
| 25 | + image_data = response.content |
| 26 | +else: |
| 27 | + print("Failed to download the image") |
| 28 | + image_data = None |
| 29 | + |
| 30 | +if image_data: |
| 31 | + # Save the image to a file |
| 32 | + with open("/murica.bmp", "wb") as file: |
| 33 | + file.write(image_data) |
| 34 | + |
| 35 | + # Load the image |
| 36 | + bitmap = displayio.OnDiskBitmap("murica.bmp") |
12 | 37 |
|
13 |
| -# Create a TileGrid to hold the image |
14 |
| -tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader) |
| 38 | + # Create a TileGrid to hold the image |
| 39 | + tile_grid = displayio.TileGrid(bitmap, pixel_shader=bitmap.pixel_shader) |
15 | 40 |
|
16 |
| -# Calculate the position to center the image |
17 |
| -# MagTag display is 296x128 pixels |
18 |
| -image_width = bitmap.width |
19 |
| -image_height = bitmap.height |
20 |
| -display_width = magtag.display.width |
21 |
| -display_height = magtag.display.height |
| 41 | + # Calculate the position to center the image |
| 42 | + # MagTag display is 296x128 pixels |
| 43 | + image_width = bitmap.width |
| 44 | + image_height = bitmap.height |
| 45 | + display_width = magtag.display.width |
| 46 | + display_height = magtag.display.height |
22 | 47 |
|
23 |
| -x = (display_width - image_width) // 2 |
24 |
| -y = (display_height - image_height) // 2 |
| 48 | + x = (display_width - image_width) // 2 |
| 49 | + y = (display_height - image_height) // 2 |
25 | 50 |
|
26 |
| -# Set the position of the TileGrid |
27 |
| -tile_grid.x = x |
28 |
| -tile_grid.y = y |
| 51 | + # Set the position of the TileGrid |
| 52 | + tile_grid.x = x |
| 53 | + tile_grid.y = y |
29 | 54 |
|
30 |
| -# Create a Group to hold the TileGrid |
31 |
| -group = displayio.Group() |
| 55 | + # Create a Group to hold the TileGrid |
| 56 | + group = displayio.Group() |
32 | 57 |
|
33 |
| -# Add the TileGrid to the Group |
34 |
| -group.append(tile_grid) |
| 58 | + # Add the TileGrid to the Group |
| 59 | + group.append(tile_grid) |
35 | 60 |
|
36 |
| -# Show the Group on the display |
37 |
| -magtag.splash.append(group) |
| 61 | + # Show the Group on the display |
| 62 | + magtag.splash.append(group) |
38 | 63 |
|
39 |
| -# Refresh the display to show the image |
40 |
| -magtag.display.refresh() |
| 64 | + # Refresh the display to show the image |
| 65 | + magtag.display.refresh() |
41 | 66 |
|
42 |
| -# Wait for the display to finish updating |
43 |
| -time.sleep(10) |
| 67 | + # Wait for the display to finish updating |
| 68 | + time.sleep(10) |
44 | 69 |
|
45 |
| -# go into sleep mode until we rotate |
46 |
| -# the photo 24 hours later |
47 |
| -#magtag.exit_and_deep_sleep(86400) |
48 |
| -magtag.exit_and_deep_sleep(5) |
| 70 | + # go into sleep mode until we rotate |
| 71 | + # the photo 24 hours later |
| 72 | + magtag.exit_and_deep_sleep(86400) |
0 commit comments