commit a1af89eef1d75f3930aef5079a7a3f7e03c534d0 Author: Bradley Bickford Date: Tue Mar 31 10:19:59 2026 -0400 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..89cc49c --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.pio +.vscode/.browse.c_cpp.db* +.vscode/c_cpp_properties.json +.vscode/launch.json +.vscode/ipch diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..080e70d --- /dev/null +++ b/.vscode/extensions.json @@ -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" + ] +} diff --git a/diagram.json b/diagram.json new file mode 100644 index 0000000..767a6ad --- /dev/null +++ b/diagram.json @@ -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"]] + ] +} diff --git a/include/Animation.h b/include/Animation.h new file mode 100644 index 0000000..50b9f6e --- /dev/null +++ b/include/Animation.h @@ -0,0 +1,75 @@ +#ifndef ANIMATION_H +#define ANIMATION_H + +#include +#include + +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 \ No newline at end of file diff --git a/include/Bitmaps.h b/include/Bitmaps.h new file mode 100644 index 0000000..a49df1c --- /dev/null +++ b/include/Bitmaps.h @@ -0,0 +1,17 @@ +#ifndef BITMAPS_H +#define BITMAPS_H + +#include + +const uint8_t teamLogoBitmap[] = { + 0b11100111, + 0b11000011, + 0b10100101, + 0b00011000, + 0b00011000, + 0b10100101, + 0b11000011, + 0b11100111 +}; + +#endif \ No newline at end of file diff --git a/include/GlobalSettings.h b/include/GlobalSettings.h new file mode 100644 index 0000000..56895dd --- /dev/null +++ b/include/GlobalSettings.h @@ -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 \ No newline at end of file diff --git a/include/README b/include/README new file mode 100644 index 0000000..49819c0 --- /dev/null +++ b/include/README @@ -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 diff --git a/include/SlidingSquarePackedBitmap.h b/include/SlidingSquarePackedBitmap.h new file mode 100644 index 0000000..7cfb003 --- /dev/null +++ b/include/SlidingSquarePackedBitmap.h @@ -0,0 +1,38 @@ +#ifndef SLIDINGSQUAREPACKEDBITMAP_H +#define SLIDINGSQUAREPACKEDBITMAP_H + +#include +#include +#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 \ No newline at end of file diff --git a/include/Utilities.h b/include/Utilities.h new file mode 100644 index 0000000..1e145f0 --- /dev/null +++ b/include/Utilities.h @@ -0,0 +1,86 @@ +#ifndef UTILITIES_H +#define UTILITIES_H + +#include +#include +#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 \ No newline at end of file diff --git a/lib/README b/lib/README new file mode 100644 index 0000000..9379397 --- /dev/null +++ b/lib/README @@ -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 +#include + +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 diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..359f99e --- /dev/null +++ b/platformio.ini @@ -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 \ No newline at end of file diff --git a/src/SlidingSquarePackedBitmap.cpp b/src/SlidingSquarePackedBitmap.cpp new file mode 100644 index 0000000..f3e0606 --- /dev/null +++ b/src/SlidingSquarePackedBitmap.cpp @@ -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; + } +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..9822aec --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,36 @@ +#include +#include +#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(leds, WIDTH * HEIGHT); + + sspb.enable(); +} + +void loop() { + sspb.update(leds); + + if(sspb.isFinished()) { + sspb.reinitialize(); + } + + FastLED.show(); + + delayMicroseconds(500); +} \ No newline at end of file diff --git a/test/README b/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/test/README @@ -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 diff --git a/wokwi.toml b/wokwi.toml new file mode 100644 index 0000000..8368011 --- /dev/null +++ b/wokwi.toml @@ -0,0 +1,4 @@ +[wokwi] +version = 1 +firmware = '.pio/build/uno/firmware.hex' +elf = '.pio/build/uno/firmware.elf' \ No newline at end of file