Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UFCFVK-15-2 - Internet of things - Challenge 1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
ja3-saxby
UFCFVK-15-2 - Internet of things - Challenge 1
Commits
90b1d6bb
Commit
90b1d6bb
authored
5 years ago
by
ja3-saxby
Browse files
Options
Downloads
Patches
Plain Diff
Interactive button-pressing demo for shape-shifting without collision-detection
parent
7cf2a48d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/main.cpp
+19
-4
19 additions, 4 deletions
source/main.cpp
with
19 additions
and
4 deletions
source/main.cpp
+
19
−
4
View file @
90b1d6bb
...
...
@@ -162,17 +162,32 @@ MicroBitImage Block::image() const {
}
}
int
x
=
1
;
void
a_button_pressed
(
MicroBitEvent
)
{
x
--
;
}
void
b_button_pressed
(
MicroBitEvent
)
{
x
++
;
}
void
debug_test
()
{
// XXX: simple debug test to check my FLASH images were stored correctly
// for accurately-timed animations irrespective of framerate, track time
unsigned
long
stopwatch
=
UBIT
.
systemTime
();
unsigned
long
move_speed
=
350
;
// move down one block every 350ms
unsigned
long
move_speed
=
1000
;
// move down one block every 350ms
// set up event handlers
UBIT
.
messageBus
.
listen
(
MICROBIT_ID_BUTTON_A
,
MICROBIT_BUTTON_EVT_CLICK
,
a_button_pressed
);
UBIT
.
messageBus
.
listen
(
MICROBIT_ID_BUTTON_B
,
MICROBIT_BUTTON_EVT_CLICK
,
b_button_pressed
);
while
(
true
)
{
// scroll random blocks down the screen
Block
block
;
// make a new random Block
// starting positions:
int
x
=
1
;
int
y
=
-
3
;
// print image until scrolled down off the screen
while
(
y
<
6
)
{
...
...
@@ -183,10 +198,10 @@ void debug_test() {
unsigned
long
stopwatch_now
=
UBIT
.
systemTime
();
if
((
stopwatch_now
-
stopwatch
)
>=
move_speed
)
{
y
++
;
}
// update the "stopwatch"
stopwatch
=
stopwatch_now
;
}
}
UBIT
.
sleep
(
50
);
// 50ms sleep for 20 FPS
}
}
...
...
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