Skip to content

add magtag example #19

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 1 commit into from
Nov 25, 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
63 changes: 63 additions & 0 deletions examples/progressbar_magtag_simpletest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
Basic progressbar example script
adapted for use on MagTag.
"""
import time
import board
import displayio
import digitalio
from adafruit_progressbar import ProgressBar

# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.)
# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus
display = board.DISPLAY
time.sleep(display.time_to_refresh)

# a button will be used to advance the progress
a_btn = digitalio.DigitalInOut(board.BUTTON_A)
a_btn.direction = digitalio.Direction.INPUT
a_btn.pull = digitalio.Pull.UP

# Make the display context
splash = displayio.Group(max_size=10)
display.show(splash)

# set progress bar width and height relative to board's display
BAR_WIDTH = display.width - 40
BAR_HEIGHT = 30

x = display.width // 2 - BAR_WIDTH // 2
y = display.height // 3

# Create a new progress_bar object at (x, y)
progress_bar = ProgressBar(
x, y, BAR_WIDTH, BAR_HEIGHT, 1.0, bar_color=0x666666, outline_color=0xFFFFFF
)

# Append progress_bar to the splash group
splash.append(progress_bar)

current_progress = (time.monotonic() % 101) / 100.0
print(current_progress)
progress_bar.progress = current_progress

# refresh the display
display.refresh()

prev_a = a_btn.value
while True:
cur_a = a_btn.value
# if a_btn was just pressed down
if not cur_a and prev_a:
current_progress += 0.20
if current_progress > 1.0:
current_progress = 0.0
print(current_progress)
progress_bar.progress = current_progress

time.sleep(display.time_to_refresh)
display.refresh()
time.sleep(display.time_to_refresh)

prev_a = cur_a