Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Comp2215 Pico Display counter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hc3g21
Comp2215 Pico Display counter
Commits
eb51118d
Commit
eb51118d
authored
2 years ago
by
hc3g21
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parents
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
displayCounter.py
+69
-0
69 additions, 0 deletions
displayCounter.py
with
69 additions
and
0 deletions
displayCounter.py
0 → 100644
+
69
−
0
View file @
eb51118d
from
machine
import
Timer
,
Pin
import
math
import
random
import
utime
from
pimoroni
import
Button
from
picographics
import
PicoGraphics
,
DISPLAY_PICO_DISPLAY
,
PEN_P4
timer_count
=
0
# global variable
# We're only using a few colours so we can use a 4 bit/16 colour palette and save RAM!
display
=
PicoGraphics
(
display
=
DISPLAY_PICO_DISPLAY
,
pen_type
=
PEN_P4
,
rotate
=
0
)
display
.
set_backlight
(
0.5
)
display
.
set_font
(
"
bitmap8
"
)
button_a
=
Button
(
12
)
button_b
=
Button
(
13
)
button_x
=
Button
(
14
)
button_y
=
Button
(
15
)
lastButton
=
button_y
WHITE
=
display
.
create_pen
(
255
,
255
,
255
)
BLACK
=
display
.
create_pen
(
0
,
0
,
0
)
CYAN
=
display
.
create_pen
(
0
,
255
,
255
)
MAGENTA
=
display
.
create_pen
(
255
,
0
,
255
)
YELLOW
=
display
.
create_pen
(
255
,
255
,
0
)
GREEN
=
display
.
create_pen
(
0
,
255
,
0
)
def
interruption_handler
(
pin
):
global
timer_count
timer_count
+=
1
# sets up a handy function we can call to clear the screen
def
clear
():
display
.
set_pen
(
BLACK
)
display
.
clear
()
display
.
update
()
# set up
clear
()
while
True
:
if
button_a
.
read
():
lastButton
=
button_a
timer_count
=
0
if
button_b
.
read
():
lastButton
=
button_b
if
button_x
.
read
():
lastButton
=
button_b
if
button_y
.
read
():
lastButton
=
button_b
if
lastButton
==
button_a
:
utime
.
sleep
(
1
)
timer_count
+=
1
print
(
timer_count
)
clear
()
display
.
set_pen
(
WHITE
)
# change the pen colour
#display.text(str(round(timer_count/20)), 10, 10, 240, 4) # display some text on the screen
display
.
text
(
str
(
timer_count
),
10
,
10
,
240
,
4
)
display
.
update
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment