Skip to content

Update readme with simpler Hello World #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 18 additions & 37 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,51 +41,32 @@ Usage Example
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal

# You can display in 'GBP', 'EUR' or 'USD'
CURRENCY = "USD"
# Set up where we'll be fetching data from
DATA_SOURCE = "https://api.coindesk.com/v1/bpi/currentprice.json"
DATA_LOCATION = ["bpi", CURRENCY, "rate_float"]


def text_transform(val):
if CURRENCY == "USD":
return "$%d" % val
if CURRENCY == "EUR":
return "‎€%d" % val
if CURRENCY == "GBP":
return "£%d" % val
return "%d" % val


# the current working directory (where this file is)
cwd = ("/" + __file__).rsplit("/", 1)[0]

matrixportal = MatrixPortal(
url=DATA_SOURCE,
json_path=DATA_LOCATION,
status_neopixel=board.NEOPIXEL,
debug=True,
)
# --- Display setup ---
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=True)
Copy link
Collaborator

@makermelissa makermelissa Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the debug=True? It was intended for debugging. ;) It was accidentally left in the current code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a new user, the debug=True was valuable. I understand it's a left-over artifact, and it's one that I'm glad was there when I got started. If you feel strongly about it, I'll remove it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, I didn't realize it was so helpful. I suppose we can leave it if you like.


# Create a new label with the color and text selected
matrixportal.add_text(
text_font=terminalio.FONT,
text_position=(16, 16),
text_color=0xFFFFFF,
text_transform=text_transform,
text_position=(0, (matrixportal.graphics.display.height // 2) - 1),
scrolling=True,
)
matrixportal.preload_font(b"$012345789") # preload numbers
matrixportal.preload_font((0x00A3, 0x20AC)) # preload gbp/euro symbol

SCROLL_DELAY = 0.03

contents = [
{ 'text': 'THIS IS RED', 'color': '#cf2727'},
{ 'text': 'THIS IS BLUE', 'color': '#0846e4'},
]

while True:
try:
value = matrixportal.fetch()
print("Response is", value)
except (ValueError, RuntimeError) as e:
print("Some error occured, retrying! -", e)
for content in contents:
matrixportal.set_text(content['text'])

time.sleep(3 * 60) # wait 3 minutes
# Set the text color
matrixportal.set_text_color(content['color'])

# Scroll it
matrixportal.scroll_text(SCROLL_DELAY)

Contributing
============
Expand Down