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
14237409
Commit
14237409
authored
2 years ago
by
Malte Schmitz
Browse files
Options
Downloads
Patches
Plain Diff
Add I/O and scheduler
parent
b482a17d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
neopixel_test.txt
+37
-0
37 additions, 0 deletions
neopixel_test.txt
platformio.ini
+1
-0
1 addition, 0 deletions
platformio.ini
src/main.cpp
+68
-9
68 additions, 9 deletions
src/main.cpp
with
106 additions
and
9 deletions
neopixel_test.txt
0 → 100644
+
37
−
0
View file @
14237409
// Simple NeoPixel test. Lights just a few pixels at a time so a
// 1m strip can safely be powered from Arduino 5V pin. Arduino
// may nonetheless hiccup when LEDs are first connected and not
// accept code. So upload code first, unplug USB, connect pixels
// to GND FIRST, then +5V and digital pin 6, then re-plug USB.
// A working strip will show a few pixels moving down the line,
// cycling between red, green and blue. If you get no response,
// might be connected to wrong end of strip (the end wires, if
// any, are no indication -- look instead for the data direction
// arrows printed on the strip).
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define N_LEDS 144
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
}
static void chase(uint32_t c) {
for(uint16_t i=0; i<strip.numPixels()+4; i++) {
strip.setPixelColor(i , c); // Draw new pixel
strip.setPixelColor(i-4, 0); // Erase pixel a few steps back
strip.show();
delay(25);
}
}
void loop() {
chase(strip.Color(255, 0, 0)); // Red
chase(strip.Color(0, 255, 0)); // Green
chase(strip.Color(0, 0, 255)); // Blue
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
platformio.ini
+
1
−
0
View file @
14237409
...
...
@@ -15,5 +15,6 @@ framework = arduino
lib_deps
=
Adafruit
NeoPixel
TaskScheduler
upload_port
=
/dev/cu.wchusbserial1420
This diff is collapsed.
Click to expand it.
src/main.cpp
+
68
−
9
View file @
14237409
#include
<Arduino.h>
#include
<Adafruit_NeoPixel.h>
#include
<TaskScheduler.h>
#define NEOPIXEL_PIN 6
#define NEOPIXEL_LEN 105
// Pin A and Pin B are connected if the button is pressed.
// Pin A and Pin No are connected if no external button is connected.
#define EXTERNAL_BUTTON_PIN_A 7
#define EXTERNAL_BUTTON_PIN_B 9
#define EXTERNAL_BUTTON_PIN_NO 8
#define INTERNAL_BUTTON_PIN_A 10
#define INTERNAL_BUTTON_PIN_B 11
Adafruit_NeoPixel
pixels
(
NEOPIXEL_LEN
,
NEOPIXEL_PIN
,
NEO_GRB
+
NEO_KHZ800
);
Scheduler
scheduler
;
void
handleButton
();
Task
taskButton
(
TASK_IMMEDIATE
,
TASK_FOREVER
,
&
handleButton
);
void
handleStep
();
Task
taskStep
(
25
,
TASK_FOREVER
,
&
handleStep
);
void
setup
()
{
pinMode
(
LED_BUILTIN
,
OUTPUT
);
pinMode
(
EXTERNAL_BUTTON_PIN_A
,
OUTPUT
);
digitalWrite
(
EXTERNAL_BUTTON_PIN_A
,
LOW
);
pinMode
(
EXTERNAL_BUTTON_PIN_B
,
INPUT_PULLUP
);
pinMode
(
EXTERNAL_BUTTON_PIN_NO
,
INPUT_PULLUP
);
pinMode
(
INTERNAL_BUTTON_PIN_A
,
OUTPUT
);
digitalWrite
(
INTERNAL_BUTTON_PIN_A
,
LOW
);
pinMode
(
INTERNAL_BUTTON_PIN_B
,
INPUT_PULLUP
);
pixels
.
begin
();
scheduler
.
init
();
scheduler
.
addTask
(
taskButton
);
taskButton
.
enable
();
scheduler
.
addTask
(
taskStep
);
taskStep
.
enable
();
}
int
pos
=
0
;
void
loop
()
{
scheduler
.
execute
();
}
uint32_t
color
=
0xFFFFFF
;
int
position
=
0
;
void
show
()
{
for
(
int
i
=
0
;
i
<
NEOPIXEL_LEN
;
i
++
)
{
pixels
.
setPixelColor
(
i
,
0xFFFFFF
);
pixels
.
setPixelColor
(
i
,
0
);
}
for
(
int
i
=
position
;
i
<
position
+
10
;
i
++
)
{
pixels
.
setPixelColor
(
i
,
color
);
}
pixels
.
setPixelColor
(
pos
,
0xFF0000
);
pixels
.
show
();
pos
=
(
pos
+
1
)
%
NEOPIXEL_LEN
;
}
digitalWrite
(
LED_BUILTIN
,
HIGH
);
delay
(
500
);
digitalWrite
(
LED_BUILTIN
,
LOW
);
delay
(
500
);
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
;
}
show
();
}
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
;
}
}
}
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