Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
1
1dpong
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Show more breadcrumbs
malte
1dpong
Commits
3c0e703a
Commit
3c0e703a
authored
2 years ago
by
Malte Schmitz
Browse files
Options
Downloads
Patches
Plain Diff
Add first simple game logic
parent
14237409
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
src/main.cpp
+59
-23
59 additions, 23 deletions
src/main.cpp
with
59 additions
and
23 deletions
src/main.cpp
+
59
−
23
View file @
3c0e703a
...
...
@@ -45,43 +45,79 @@ void loop() {
scheduler
.
execute
();
}
uint32_t
color
=
0xFFFFFF
;
int
position
=
0
;
int
last_internal_button_state
=
HIGH
;
int
last_external_button_state
=
HIGH
;
unsigned
long
last_internal_button_pressed
=
0
;
unsigned
long
last_external_button_pressed
=
0
;
#define STATE_PAUSE 0
#define STATE_FORWARD 1
#define STATE_BACKWARD 2
int
state
=
STATE_PAUSE
;
void
show
()
{
for
(
int
i
=
0
;
i
<
NEOPIXEL_LEN
;
i
++
)
{
pixels
.
setPixelColor
(
i
,
0
);
}
for
(
int
i
=
position
;
i
<
position
+
10
;
i
++
)
{
pixels
.
setPixelColor
(
i
,
color
);
if
(
state
>
STATE_PAUSE
)
{
pixels
.
setPixelColor
(
position
,
0xFFFFFF
);
}
pixels
.
show
();
}
void
handleButton
()
{
if
(
digitalRead
(
INTERNAL_BUTTON_PIN_B
)
==
LOW
)
{
color
=
0x0000FF
;
}
else
if
(
digitalRead
(
EXTERNAL_BUTTON_PIN_NO
)
==
LOW
)
{
color
=
0xFF0000
;
}
else
if
(
digitalRead
(
EXTERNAL_BUTTON_PIN_B
)
==
LOW
)
{
color
=
0x00FF00
;
int
current_internal_button_state
=
digitalRead
(
INTERNAL_BUTTON_PIN_B
);
int
current_external_button_state
=
digitalRead
(
EXTERNAL_BUTTON_PIN_B
);
if
(
last_internal_button_state
==
HIGH
&&
current_internal_button_state
==
LOW
)
{
last_internal_button_pressed
=
millis
();
}
show
();
if
(
last_external_button_state
==
HIGH
&&
current_external_button_state
==
LOW
)
{
last_external_button_pressed
=
millis
();
}
last_internal_button_state
=
current_internal_button_state
;
last_external_button_state
=
current_external_button_state
;
}
boolean
forward
=
true
;
void
handleStep
()
{
if
(
forward
)
{
position
=
position
+
1
;
if
(
position
>
NEOPIXEL_LEN
-
11
)
{
position
=
position
-
2
;
forward
=
false
;
}
}
else
{
position
=
position
-
1
;
if
(
position
<
0
)
{
position
=
1
;
forward
=
true
;
}
unsigned
long
now
=
millis
();
switch
(
state
)
{
case
STATE_PAUSE
:
if
(
now
-
last_internal_button_pressed
<
100
)
{
position
=
0
;
state
=
STATE_FORWARD
;
}
if
(
now
-
last_external_button_pressed
<
100
)
{
position
=
NEOPIXEL_LEN
-
1
;
state
=
STATE_BACKWARD
;
}
break
;
case
STATE_FORWARD
:
position
=
position
+
1
;
if
(
position
>
NEOPIXEL_LEN
-
1
)
{
if
(
now
-
last_external_button_pressed
<
100
)
{
position
=
position
-
2
;
state
=
STATE_BACKWARD
;
}
else
{
state
=
STATE_PAUSE
;
}
}
break
;
case
STATE_BACKWARD
:
position
=
position
-
1
;
if
(
position
<
0
)
{
if
(
now
-
last_internal_button_pressed
<
100
)
{
position
=
1
;
state
=
STATE_FORWARD
;
}
else
{
state
=
STATE_PAUSE
;
}
}
break
;
}
show
();
}
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