kopia lustrzana https://github.com/pimoroni/pimoroni-pico
commit
8e91108ce5
|
|
@ -1,8 +1,9 @@
|
|||
# This example shows you a simple, non-interrupt way of reading Inky Frame's buttons with a loop that checks to see if buttons are pressed.
|
||||
|
||||
from pimoroni import ShiftRegister
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
|
||||
from machine import Pin
|
||||
|
||||
display = PicoGraphics(display=DISPLAY)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ from network_manager import NetworkManager
|
|||
import uasyncio
|
||||
import ujson
|
||||
from urllib import urequest
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
|
||||
from machine import Pin
|
||||
from pimoroni_i2c import PimoroniI2C
|
||||
from pcf85063a import PCF85063A
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
|
||||
from network_manager import NetworkManager
|
||||
import uasyncio
|
||||
from urllib import urequest
|
||||
|
|
@ -173,11 +174,11 @@ while True:
|
|||
graphics.text(feed[2]["description"], 10, 395 if graphics.measure_text(feed[2]["title"]) < 650 else 375, WIDTH - 150, 2)
|
||||
|
||||
code.set_text(feed[0]["guid"])
|
||||
draw_qr_code(490, 40, 100, code)
|
||||
draw_qr_code(WIDTH - 110, 40, 100, code)
|
||||
code.set_text(feed[1]["guid"])
|
||||
draw_qr_code(10, 180, 100, code)
|
||||
code.set_text(feed[2]["guid"])
|
||||
draw_qr_code(490, 320, 100, code)
|
||||
draw_qr_code(WIDTH - 110, 320, 100, code)
|
||||
|
||||
else:
|
||||
graphics.set_pen(4)
|
||||
|
|
|
|||
|
|
@ -8,8 +8,9 @@ import sdcard
|
|||
import WIFI_CONFIG
|
||||
from urllib import urequest
|
||||
from network_manager import NetworkManager
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
|
||||
|
||||
"""
|
||||
random placekitten (from a very small set)
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ import uasyncio
|
|||
import WIFI_CONFIG
|
||||
from urllib import urequest
|
||||
from network_manager import NetworkManager
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
|
||||
|
||||
|
||||
ENDPOINT = "https://en.wikiquote.org/w/api.php?format=json&action=expandtemplates&prop=wikitext&text={{{{Wikiquote:Quote%20of%20the%20day/{3}%20{2},%20{0}}}}}"
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ import jpegdec
|
|||
import WIFI_CONFIG
|
||||
import uasyncio
|
||||
from network_manager import NetworkManager
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
|
||||
from urllib import urequest
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ import sdcard
|
|||
import WIFI_CONFIG
|
||||
from urllib import urequest
|
||||
from network_manager import NetworkManager
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
|
||||
|
||||
"""
|
||||
xkcd daily
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ from machine import reset
|
|||
import inky_helper as ih
|
||||
|
||||
# Uncomment the line for your Inky Frame display size
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME_4 as DISPLAY # 4.0"
|
||||
# from picographics import PicoGraphics, DISPLAY_INKY_FRAME as DISPLAY # 5.7"
|
||||
from picographics import PicoGraphics, DISPLAY_INKY_FRAME_7 as DISPLAY # 7.3"
|
||||
|
||||
# Create a secrets.py with your Wifi details to be able to get the time
|
||||
#
|
||||
|
|
@ -27,6 +28,10 @@ def launcher():
|
|||
# Apply an offset for the Inky Frame 5.7".
|
||||
if HEIGHT == 448:
|
||||
y_offset = 20
|
||||
# Inky Frame 7.3"
|
||||
elif HEIGHT == 480:
|
||||
y_offset = 35
|
||||
# Inky Frame 4"
|
||||
else:
|
||||
y_offset = 0
|
||||
|
||||
|
|
@ -35,11 +40,12 @@ def launcher():
|
|||
graphics.clear()
|
||||
graphics.set_pen(0)
|
||||
|
||||
graphics.set_pen(5)
|
||||
graphics.set_pen(graphics.create_pen(255, 215, 0))
|
||||
graphics.rectangle(0, 0, WIDTH, 50)
|
||||
graphics.set_pen(0)
|
||||
len = graphics.measure_text("Launcher", 4) // 2
|
||||
graphics.text("Launcher", (WIDTH // 2 - len), 10, WIDTH, 4)
|
||||
title = "Launcher"
|
||||
title_len = graphics.measure_text(title, 4) // 2
|
||||
graphics.text(title, (WIDTH // 2 - title_len), 10, WIDTH, 4)
|
||||
|
||||
graphics.set_pen(4)
|
||||
graphics.rectangle(30, HEIGHT - (340 + y_offset), WIDTH - 100, 50)
|
||||
|
|
@ -66,7 +72,7 @@ def launcher():
|
|||
graphics.set_pen(1)
|
||||
graphics.text("E. Random Joke", 35, HEIGHT - (85 + y_offset), 600, 3)
|
||||
|
||||
graphics.set_pen(7)
|
||||
graphics.set_pen(graphics.create_pen(220, 220, 220))
|
||||
graphics.rectangle(WIDTH - 100, HEIGHT - (340 + y_offset), 70, 50)
|
||||
graphics.rectangle(WIDTH - 150, HEIGHT - (280 + y_offset), 120, 50)
|
||||
graphics.rectangle(WIDTH - 200, HEIGHT - (220 + y_offset), 170, 50)
|
||||
|
|
@ -74,7 +80,9 @@ def launcher():
|
|||
graphics.rectangle(WIDTH - 300, HEIGHT - (100 + y_offset), 270, 50)
|
||||
|
||||
graphics.set_pen(0)
|
||||
graphics.text("Hold A + E, then press Reset, to return to the Launcher", 65, HEIGHT - 30, 600, 2)
|
||||
note = "Hold A + E, then press Reset, to return to the Launcher"
|
||||
note_len = graphics.measure_text(note, 2) // 2
|
||||
graphics.text(note, (WIDTH // 2 - note_len), HEIGHT - 30, 600, 2)
|
||||
|
||||
ih.led_warn.on()
|
||||
graphics.update()
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ def update():
|
|||
elif HEIGHT == 400:
|
||||
# Image for Inky Frame 4.0
|
||||
IMG_URL = "https://pimoroni.github.io/feed2image/nasa-apod-640x400-daily.jpg"
|
||||
elif HEIGHT == 480:
|
||||
IMG_URL = "https://pimoroni.github.io/feed2image/nasa-apod-800x480-daily.jpg"
|
||||
|
||||
try:
|
||||
# Grab the data
|
||||
|
|
|
|||
|
|
@ -138,6 +138,9 @@ def draw():
|
|||
if feed:
|
||||
|
||||
# Title
|
||||
graphics.set_pen(graphics.create_pen(200, 0, 0))
|
||||
graphics.rectangle(0, 0, WIDTH, 40)
|
||||
graphics.set_pen(1)
|
||||
graphics.text("Headlines from BBC News:", 10, 10, 320, 3)
|
||||
|
||||
graphics.set_pen(4)
|
||||
|
|
@ -155,6 +158,9 @@ def draw():
|
|||
code.set_text(feed[1]["guid"])
|
||||
draw_qr_code(10, 265, 100, code)
|
||||
|
||||
graphics.set_pen(graphics.create_pen(200, 0, 0))
|
||||
graphics.rectangle(0, HEIGHT - 20, WIDTH, 20)
|
||||
|
||||
else:
|
||||
graphics.set_pen(4)
|
||||
graphics.rectangle(0, (HEIGHT // 2) - 20, WIDTH, 40)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import gc
|
||||
import random
|
||||
import jpegdec
|
||||
from urllib import urequest
|
||||
from ujson import load
|
||||
import qrcode
|
||||
|
||||
gc.collect() # We're really gonna need that RAM!
|
||||
|
||||
|
|
@ -13,19 +14,39 @@ HEIGHT = 0
|
|||
FILENAME = "random-joke.jpg"
|
||||
|
||||
JOKE_IDS = "https://pimoroni.github.io/feed2image/jokeapi-ids.txt"
|
||||
JOKE_IMG = "https://pimoroni.github.io/feed2image/jokeapi-{}-{}x{}.jpg"
|
||||
JOKE_IMG = "https://pimoroni.github.io/feed2image/jokeapi-{}.json"
|
||||
|
||||
UPDATE_INTERVAL = 60
|
||||
|
||||
gc.collect() # Claw back some RAM!
|
||||
|
||||
|
||||
# We don't have the RAM to store the list of Joke IDs in memory.
|
||||
# the first line of `jokeapi-ids.txt` is a COUNT of IDs.
|
||||
# Grab it, then pick a random line between 0 and COUNT.
|
||||
# Seek to that line and ...y'know... there's our totally random joke ID
|
||||
|
||||
joke = []
|
||||
|
||||
|
||||
def measure_qr_code(size, code):
|
||||
w, h = code.get_size()
|
||||
module_size = int(size / w)
|
||||
return module_size * w, module_size
|
||||
|
||||
|
||||
def draw_qr_code(ox, oy, size, code):
|
||||
size, module_size = measure_qr_code(size, code)
|
||||
graphics.set_pen(1)
|
||||
graphics.rectangle(ox, oy, size, size)
|
||||
graphics.set_pen(0)
|
||||
for x in range(size):
|
||||
for y in range(size):
|
||||
if code.get_module(x, y):
|
||||
graphics.rectangle(ox + x * module_size, oy + y * module_size, module_size, module_size)
|
||||
|
||||
|
||||
def update():
|
||||
global joke
|
||||
|
||||
try:
|
||||
socket = urequest.urlopen(JOKE_IDS)
|
||||
|
|
@ -49,34 +70,48 @@ def update():
|
|||
|
||||
print("Random joke ID: {}".format(random_joke_id))
|
||||
|
||||
url = JOKE_IMG.format(random_joke_id, WIDTH, HEIGHT)
|
||||
url = JOKE_IMG.format(random_joke_id)
|
||||
|
||||
socket = urequest.urlopen(url)
|
||||
gc.collect()
|
||||
|
||||
# Stream the image data from the socket onto disk in 1024 byte chunks
|
||||
# the 600x448-ish jpeg will be roughly ~24k, we really don't have the RAM!
|
||||
data = bytearray(1024)
|
||||
with open(FILENAME, "wb") as f:
|
||||
while True:
|
||||
if socket.readinto(data) == 0:
|
||||
break
|
||||
f.write(data)
|
||||
socket.close()
|
||||
del data
|
||||
gc.collect() # We really are tight on RAM!
|
||||
# Grab the data
|
||||
try:
|
||||
socket = urequest.urlopen(url)
|
||||
gc.collect()
|
||||
j = load(socket)
|
||||
socket.close()
|
||||
joke = j
|
||||
del j
|
||||
gc.collect()
|
||||
except OSError as e:
|
||||
print(e)
|
||||
|
||||
|
||||
def draw():
|
||||
jpeg = jpegdec.JPEG(graphics)
|
||||
gc.collect() # For good measure...
|
||||
|
||||
code = qrcode.QRCode()
|
||||
graphics.set_pen(1)
|
||||
graphics.clear()
|
||||
|
||||
try:
|
||||
jpeg.open_file(FILENAME)
|
||||
jpeg.decode()
|
||||
except OSError:
|
||||
if joke:
|
||||
if joke['type'] == "single":
|
||||
graphics.set_pen(4)
|
||||
graphics.text(joke['joke'], 10, 10, WIDTH - 75, 5)
|
||||
if joke['type'] == "twopart":
|
||||
graphics.set_pen(4)
|
||||
graphics.text(joke['setup'], 10, 10, WIDTH - 75, 5)
|
||||
graphics.set_pen(3)
|
||||
graphics.text(joke['delivery'], 10, 250, WIDTH - 75, 5)
|
||||
|
||||
graphics.set_pen(0)
|
||||
# Donate link QR
|
||||
code.set_text("https://github.com/sponsors/Sv443")
|
||||
draw_qr_code(WIDTH - 75, HEIGHT - 75, 75, code)
|
||||
|
||||
graphics.text("curated by jokeapi.dev", 10, HEIGHT - 15, WIDTH, 1)
|
||||
graphics.text("donate <3", WIDTH - 65, HEIGHT - 12, WIDTH, 1)
|
||||
|
||||
else:
|
||||
graphics.set_pen(4)
|
||||
graphics.rectangle(0, (HEIGHT // 2) - 20, WIDTH, 40)
|
||||
graphics.set_pen(1)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
# secrets.py should contain:
|
||||
WIFI_SSID = ""
|
||||
WIFI_PASSWORD = ""
|
||||
|
|
@ -34,7 +34,10 @@ def approx_time(hours, minutes):
|
|||
def update():
|
||||
global time_string
|
||||
# grab the current time from the ntp server and update the Pico RTC
|
||||
ntptime.settime()
|
||||
try:
|
||||
ntptime.settime()
|
||||
except OSError:
|
||||
print("Unable to contact NTP server")
|
||||
|
||||
current_t = rtc.datetime()
|
||||
time_string = approx_time(current_t[4] - 12 if current_t[4] > 12 else current_t[4], current_t[5])
|
||||
|
|
@ -63,6 +66,12 @@ def draw():
|
|||
y = 10
|
||||
line_space = 70
|
||||
letter_space = 40
|
||||
elif WIDTH == 800:
|
||||
default_x = 5
|
||||
x = default_x
|
||||
y = 70
|
||||
line_space = 60
|
||||
letter_space = 50
|
||||
else: # Inky Frame 5.7"
|
||||
default_x = 20
|
||||
x = default_x
|
||||
|
|
@ -78,7 +87,7 @@ def draw():
|
|||
if word in time_string:
|
||||
graphics.set_pen(0)
|
||||
else:
|
||||
graphics.set_pen(7)
|
||||
graphics.set_pen(graphics.create_pen(220, 220, 220))
|
||||
|
||||
for letter in word:
|
||||
text_length = graphics.measure_text(letter, scale, spacing)
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue