Skip to content

Commit 1081903

Browse files
authored
Merge pull request #3148 from FoamyGuy/fruit_jam_quotes_example
Fruit Jam quotes example
2 parents bc68519 + a581736 commit 1081903

File tree

3 files changed

+59305
-0
lines changed

3 files changed

+59305
-0
lines changed

Fruit_Jam/Fruit_Jam_Quotes/code.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2025 Tim Cocks for Adafruit Industries
3+
#
4+
# SPDX-License-Identifier: MIT
5+
"""
6+
Quotes example originally for PyPortal adapted for Fruit Jam
7+
"""
8+
import time
9+
import board
10+
from adafruit_fruitjam import FruitJam
11+
from adafruit_fruitjam.peripherals import request_display_config
12+
13+
request_display_config(320, 240)
14+
15+
# Set up where we'll be fetching data from
16+
DATA_SOURCE = "https://www.adafruit.com/api/quotes.php"
17+
QUOTE_LOCATION = [0, 'text']
18+
AUTHOR_LOCATION = [0, 'author']
19+
20+
# the current working directory (where this file is)
21+
cwd = ("/"+__file__).rsplit('/', 1)[0]
22+
fruitjam = FruitJam(url=DATA_SOURCE,
23+
json_path=(QUOTE_LOCATION, AUTHOR_LOCATION),
24+
status_neopixel=board.NEOPIXEL,
25+
default_bg=cwd+"/quote_background.bmp",
26+
text_font=cwd+"/fonts/Arial-ItalicMT-17.bdf",
27+
text_position=((20, 120), # quote location
28+
(5, 200)), # author location
29+
text_color=(0xFFFFFF, # quote text color
30+
0x8080FF), # author text color
31+
text_wrap=(35, # characters to wrap for quote
32+
0), # no wrap for author
33+
text_maxlen=(180, 30), # max text size for quote & author
34+
)
35+
36+
# speed up projects with lots of text by preloading the font!
37+
fruitjam.preload_font()
38+
39+
while True:
40+
try:
41+
value = fruitjam.fetch()
42+
print("Response is", value)
43+
except (ValueError, RuntimeError, ConnectionError, OSError) as e:
44+
print("Some error occured, retrying! -", e)
45+
time.sleep(60)

0 commit comments

Comments
 (0)