Initial Commit
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
10
.vscode/extensions.json
vendored
Normal file
10
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
||||||
29
diagram.json
Normal file
29
diagram.json
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"author": "Uri Shaked",
|
||||||
|
"editor": "wokwi",
|
||||||
|
"parts": [
|
||||||
|
{
|
||||||
|
"id": "uno",
|
||||||
|
"type": "wokwi-arduino-uno",
|
||||||
|
"top": 45,
|
||||||
|
"left": 375
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "neopixels",
|
||||||
|
"type": "wokwi-neopixel-canvas",
|
||||||
|
"top": 0,
|
||||||
|
"left": 0,
|
||||||
|
"attrs": {
|
||||||
|
"rows": "8",
|
||||||
|
"cols": "32",
|
||||||
|
"matrixBrightness": "10"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"connections": [
|
||||||
|
["uno:GND.1", "neopixels:VSS", "black", ["v0", "*", "v16"]],
|
||||||
|
["uno:6", "neopixels:DIN", "green", ["v-16", "*", "v8"]],
|
||||||
|
["uno:5V", "neopixels:VDD", "red", ["v20", "h-95", "*", "v8"]]
|
||||||
|
]
|
||||||
|
}
|
||||||
75
include/Animation.h
Normal file
75
include/Animation.h
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#ifndef ANIMATION_H
|
||||||
|
#define ANIMATION_H
|
||||||
|
|
||||||
|
#include <FastLED.h>
|
||||||
|
#include <elapsedMillis.h>
|
||||||
|
|
||||||
|
class Animation {
|
||||||
|
public:
|
||||||
|
Animation(long _updateTime, uint16_t _finishedAfterCycles) : updateTime(_updateTime),
|
||||||
|
finishedAfterCycles(_finishedAfterCycles), cycles(0), enabled(false),
|
||||||
|
initialized(false), timer(0) {}
|
||||||
|
|
||||||
|
virtual void initialize(CRGB* leds) {}
|
||||||
|
virtual void execute(CRGB* leds) {}
|
||||||
|
virtual bool isFinished() {
|
||||||
|
return cycles > finishedAfterCycles;
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(CRGB* leds) {
|
||||||
|
if(enabled) {
|
||||||
|
if(timer >= updateTime) {
|
||||||
|
if(!initialized) {
|
||||||
|
initialize(leds);
|
||||||
|
cycles = 0;
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isFinished()) {
|
||||||
|
execute(leds);
|
||||||
|
}
|
||||||
|
|
||||||
|
resetTimer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void enable() {
|
||||||
|
enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void disable() {
|
||||||
|
enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reinitialize() {
|
||||||
|
initialized = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void resetTimer() {
|
||||||
|
timer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cycleCompleted() {
|
||||||
|
cycles = cycles += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
long
|
||||||
|
updateTime;
|
||||||
|
uint16_t
|
||||||
|
cycles,
|
||||||
|
finishedAfterCycles;
|
||||||
|
bool
|
||||||
|
enabled,
|
||||||
|
initialized;
|
||||||
|
elapsedMillis
|
||||||
|
timer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
17
include/Bitmaps.h
Normal file
17
include/Bitmaps.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef BITMAPS_H
|
||||||
|
#define BITMAPS_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
const uint8_t teamLogoBitmap[] = {
|
||||||
|
0b11100111,
|
||||||
|
0b11000011,
|
||||||
|
0b10100101,
|
||||||
|
0b00011000,
|
||||||
|
0b00011000,
|
||||||
|
0b10100101,
|
||||||
|
0b11000011,
|
||||||
|
0b11100111
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
9
include/GlobalSettings.h
Normal file
9
include/GlobalSettings.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#ifndef GLOBALSETTINGS_H
|
||||||
|
#define GLOBALSETTINGS_H
|
||||||
|
|
||||||
|
#define WIDTH 32
|
||||||
|
#define HEIGHT 8
|
||||||
|
#define OUTPUT_PIN 6
|
||||||
|
#define MODE XYModes::HORIZONTALSCAN
|
||||||
|
|
||||||
|
#endif
|
||||||
37
include/README
Normal file
37
include/README
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
This directory is intended for project header files.
|
||||||
|
|
||||||
|
A header file is a file containing C declarations and macro definitions
|
||||||
|
to be shared between several project source files. You request the use of a
|
||||||
|
header file in your project source file (C, C++, etc) located in `src` folder
|
||||||
|
by including it, with the C preprocessing directive `#include'.
|
||||||
|
|
||||||
|
```src/main.c
|
||||||
|
|
||||||
|
#include "header.h"
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Including a header file produces the same results as copying the header file
|
||||||
|
into each source file that needs it. Such copying would be time-consuming
|
||||||
|
and error-prone. With a header file, the related declarations appear
|
||||||
|
in only one place. If they need to be changed, they can be changed in one
|
||||||
|
place, and programs that include the header file will automatically use the
|
||||||
|
new version when next recompiled. The header file eliminates the labor of
|
||||||
|
finding and changing all the copies as well as the risk that a failure to
|
||||||
|
find one copy will result in inconsistencies within a program.
|
||||||
|
|
||||||
|
In C, the convention is to give header files names that end with `.h'.
|
||||||
|
|
||||||
|
Read more about using header files in official GCC documentation:
|
||||||
|
|
||||||
|
* Include Syntax
|
||||||
|
* Include Operation
|
||||||
|
* Once-Only Headers
|
||||||
|
* Computed Includes
|
||||||
|
|
||||||
|
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||||
38
include/SlidingSquarePackedBitmap.h
Normal file
38
include/SlidingSquarePackedBitmap.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#ifndef SLIDINGSQUAREPACKEDBITMAP_H
|
||||||
|
#define SLIDINGSQUAREPACKEDBITMAP_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <FastLED.h>
|
||||||
|
#include "GlobalSettings.h"
|
||||||
|
#include "Animation.h"
|
||||||
|
#include "Utilities.h"
|
||||||
|
|
||||||
|
class SlidingSquarePackedBitmap : public Animation {
|
||||||
|
public:
|
||||||
|
SlidingSquarePackedBitmap(long _updateTime, const uint8_t* _bitmap, CRGB _color) :
|
||||||
|
Animation(_updateTime, (WIDTH - 8) * 2 * 5), bitmap(_bitmap), color(_color),
|
||||||
|
currentX(0), currentDirection(1) {}
|
||||||
|
|
||||||
|
void initialize(CRGB* leds) {
|
||||||
|
currentX = 0;
|
||||||
|
currentDirection = 1;
|
||||||
|
|
||||||
|
resetTimer();
|
||||||
|
|
||||||
|
Utilities::setAll(leds, MODE, CRGB::Black);
|
||||||
|
}
|
||||||
|
|
||||||
|
void execute(CRGB* leds);
|
||||||
|
|
||||||
|
private:
|
||||||
|
const uint8_t*
|
||||||
|
bitmap;
|
||||||
|
uint16_t
|
||||||
|
currentX;
|
||||||
|
int8_t
|
||||||
|
currentDirection;
|
||||||
|
CRGB
|
||||||
|
color;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
86
include/Utilities.h
Normal file
86
include/Utilities.h
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
#ifndef UTILITIES_H
|
||||||
|
#define UTILITIES_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <FastLED.h>
|
||||||
|
#include "GlobalSettings.h"
|
||||||
|
|
||||||
|
enum class XYModes {
|
||||||
|
HORIZONTALSCAN,
|
||||||
|
HORIZONTALSERPENTINE,
|
||||||
|
COLUMNSCAN,
|
||||||
|
COLUMNSERPENTINE
|
||||||
|
};
|
||||||
|
|
||||||
|
class Utilities {
|
||||||
|
public:
|
||||||
|
static uint16_t XY(XYModes mode, uint16_t x, uint16_t y) {
|
||||||
|
if(mode == XYModes::HORIZONTALSCAN) {
|
||||||
|
return WIDTH * y + x;
|
||||||
|
} else if(mode == XYModes::COLUMNSCAN) {
|
||||||
|
return HEIGHT * x + y;
|
||||||
|
} else if(mode == XYModes::HORIZONTALSERPENTINE) {
|
||||||
|
if(y & 0x1) {
|
||||||
|
return y * WIDTH + (WIDTH - 1 - x);
|
||||||
|
} else {
|
||||||
|
return y * WIDTH + x;
|
||||||
|
}
|
||||||
|
} else if(mode == XYModes::COLUMNSERPENTINE) {
|
||||||
|
if(x & 0x1) {
|
||||||
|
return x * HEIGHT + (HEIGHT - 1 - y);
|
||||||
|
} else {
|
||||||
|
return x * HEIGHT + y;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 0; //How did you get here?
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setArea(CRGB* leds, XYModes mode, uint16_t startX, uint16_t startY, uint16_t endX, uint16_t endY, CRGB color) {
|
||||||
|
for(uint16_t x = startX; x < endX; x++) {
|
||||||
|
for(uint16_t y = startY; y < endY; y++) {
|
||||||
|
leds[XY(mode, x, y)] = color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void setAll(CRGB* leds, XYModes mode, CRGB color) {
|
||||||
|
setArea(leds, mode, 0, 0, WIDTH, HEIGHT, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void drawPackedSquareBitmap(CRGB* leds, XYModes mode, const uint8_t* bitmap, uint16_t xOrigin, CRGB color) {
|
||||||
|
for(uint16_t y = 0; y < 8; y++) {
|
||||||
|
uint8_t mask = 0x80;
|
||||||
|
for(uint16_t x = xOrigin; x < xOrigin + 8; x++) {
|
||||||
|
if((bitmap[y] & mask) != 0) {
|
||||||
|
leds[XY(mode, x, y)] = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
mask >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void drawPackedFullFrameBitmap(CRGB* leds, XYModes mode, const uint32_t* bitmap, CRGB color) {
|
||||||
|
for(uint16_t y = 0; y < 8; y++) {
|
||||||
|
uint32_t mask = 0x80000000;
|
||||||
|
for(uint16_t x = 0; x < 32; x++) {
|
||||||
|
if((bitmap[y] & mask) != 0) {
|
||||||
|
leds[XY(mode, x, y)] = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
mask >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void drawFullFrameIndexedMap(CRGB* leds, XYModes mode, uint8_t** indexMap, CRGB* colors) {
|
||||||
|
for(uint16_t x = 0; x < WIDTH; x++) {
|
||||||
|
for(uint16_t y = 0; y < HEIGHT; y++) {
|
||||||
|
leds[XY(mode, x, y)] = colors[indexMap[x][y]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
46
lib/README
Normal file
46
lib/README
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into the executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a separate directory
|
||||||
|
("lib/your_library_name/[Code]").
|
||||||
|
|
||||||
|
For example, see the structure of the following example libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional. for custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||||
|
| |
|
||||||
|
| |--Foo
|
||||||
|
| | |- Foo.c
|
||||||
|
| | |- Foo.h
|
||||||
|
| |
|
||||||
|
| |- README --> THIS FILE
|
||||||
|
|
|
||||||
|
|- platformio.ini
|
||||||
|
|--src
|
||||||
|
|- main.c
|
||||||
|
|
||||||
|
Example contents of `src/main.c` using Foo and Bar:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
The PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries by scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
25
platformio.ini
Normal file
25
platformio.ini
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
; PlatformIO Project Configuration File
|
||||||
|
;
|
||||||
|
; Build options: build flags, source filter
|
||||||
|
; Upload options: custom upload port, speed and extra flags
|
||||||
|
; Library options: dependencies, extra library storages
|
||||||
|
; Advanced options: extra scripting
|
||||||
|
;
|
||||||
|
; Please visit documentation for the other options and examples
|
||||||
|
; https://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
|
[env:uno]
|
||||||
|
platform = atmelavr
|
||||||
|
board = uno
|
||||||
|
framework = arduino
|
||||||
|
lib_deps =
|
||||||
|
fastled/FastLED@^3.10.3
|
||||||
|
pfeerick/elapsedMillis@^1.0.6
|
||||||
|
|
||||||
|
[env:feather]
|
||||||
|
platform = atmelsam
|
||||||
|
board = adafruit_feather_m0
|
||||||
|
framework = arduino
|
||||||
|
lib_deps =
|
||||||
|
fastled/FastLED@^3.10.3
|
||||||
|
pfeerick/elapsedMillis@^1.0.6
|
||||||
16
src/SlidingSquarePackedBitmap.cpp
Normal file
16
src/SlidingSquarePackedBitmap.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#include "SlidingSquarePackedBitmap.h"
|
||||||
|
|
||||||
|
void SlidingSquarePackedBitmap::execute(CRGB* leds) {
|
||||||
|
Utilities::setAll(leds, MODE, CRGB::Black);
|
||||||
|
|
||||||
|
Utilities::drawPackedSquareBitmap(leds, MODE, bitmap, currentX, color);
|
||||||
|
|
||||||
|
currentX += currentDirection;
|
||||||
|
|
||||||
|
if(currentX == 0) {
|
||||||
|
currentDirection *= -1;
|
||||||
|
cycleCompleted();
|
||||||
|
} else if (currentX == 24) {
|
||||||
|
currentDirection *= -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/main.cpp
Normal file
36
src/main.cpp
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <FastLED.h>
|
||||||
|
#include "GlobalSettings.h"
|
||||||
|
#include "Utilities.h"
|
||||||
|
#include "SlidingSquarePackedBitmap.h"
|
||||||
|
#include "Bitmaps.h"
|
||||||
|
|
||||||
|
CRGB leds[WIDTH * HEIGHT];
|
||||||
|
|
||||||
|
CRGB teamColors[] = {CRGB::Orange, CRGB::Green};
|
||||||
|
|
||||||
|
XYModes mode = XYModes::HORIZONTALSCAN;
|
||||||
|
|
||||||
|
SlidingSquarePackedBitmap sspb(150, teamLogoBitmap, CRGB::Green);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(9600);
|
||||||
|
Serial.println(F("HELLO"));
|
||||||
|
FastLED.setMaxPowerInMilliWatts(400);
|
||||||
|
|
||||||
|
FastLED.addLeds<WS2812, OUTPUT_PIN, GRB>(leds, WIDTH * HEIGHT);
|
||||||
|
|
||||||
|
sspb.enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
sspb.update(leds);
|
||||||
|
|
||||||
|
if(sspb.isFinished()) {
|
||||||
|
sspb.reinitialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
FastLED.show();
|
||||||
|
|
||||||
|
delayMicroseconds(500);
|
||||||
|
}
|
||||||
11
test/README
Normal file
11
test/README
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Test Runner and project tests.
|
||||||
|
|
||||||
|
Unit Testing is a software testing method by which individual units of
|
||||||
|
source code, sets of one or more MCU program modules together with associated
|
||||||
|
control data, usage procedures, and operating procedures, are tested to
|
||||||
|
determine whether they are fit for use. Unit testing finds problems early
|
||||||
|
in the development cycle.
|
||||||
|
|
||||||
|
More information about PlatformIO Unit Testing:
|
||||||
|
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
|
||||||
4
wokwi.toml
Normal file
4
wokwi.toml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
[wokwi]
|
||||||
|
version = 1
|
||||||
|
firmware = '.pio/build/uno/firmware.hex'
|
||||||
|
elf = '.pio/build/uno/firmware.elf'
|
||||||
Reference in New Issue
Block a user