From 941c168de8b1fe0766c3637f6bedf42984a293ee Mon Sep 17 00:00:00 2001 From: tiijay Date: Mon, 3 Nov 2025 15:05:22 +0100 Subject: [PATCH] first commit --- .gitignore | 5 ++ .vscode/extensions.json | 10 +++ .vscode/settings.json | 6 ++ diagram.json | 26 +++++++ include/README | 37 +++++++++ lib/BlinkLed/library.json | 7 ++ lib/BlinkLed/src/BlinkInternLed.h | 16 ++++ lib/BlinkLed/src/BlinkLed.cpp | 25 ++++++ lib/BlinkLed/src/BlinkLed.h | 24 ++++++ lib/Fonts/library.json | 7 ++ lib/Fonts/src/font_5x7.cpp | 59 ++++++++++++++ lib/Fonts/src/font_5x7.h | 124 ++++++++++++++++++++++++++++++ lib/LedMatrix/library.json | 7 ++ lib/LedMatrix/src/LedMatrix.cpp | 11 +++ lib/LedMatrix/src/LedMatrix.h | 64 +++++++++++++++ lib/MyClass/library.json | 7 ++ lib/MyClass/src/MyClass.cpp | 18 +++++ lib/MyClass/src/MyClass.h | 16 ++++ lib/README | 46 +++++++++++ platformio.ini | 22 ++++++ src/main.cpp | 80 +++++++++++++++++++ src/main___.cpp | 94 ++++++++++++++++++++++ test/README | 11 +++ wokwi.toml | 6 ++ 24 files changed, 728 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json create mode 100644 diagram.json create mode 100644 include/README create mode 100644 lib/BlinkLed/library.json create mode 100644 lib/BlinkLed/src/BlinkInternLed.h create mode 100644 lib/BlinkLed/src/BlinkLed.cpp create mode 100644 lib/BlinkLed/src/BlinkLed.h create mode 100644 lib/Fonts/library.json create mode 100644 lib/Fonts/src/font_5x7.cpp create mode 100644 lib/Fonts/src/font_5x7.h create mode 100644 lib/LedMatrix/library.json create mode 100644 lib/LedMatrix/src/LedMatrix.cpp create mode 100644 lib/LedMatrix/src/LedMatrix.h create mode 100644 lib/MyClass/library.json create mode 100644 lib/MyClass/src/MyClass.cpp create mode 100644 lib/MyClass/src/MyClass.h create mode 100644 lib/README create mode 100644 platformio.ini create mode 100644 src/main.cpp create mode 100644 src/main___.cpp create mode 100644 test/README create mode 100644 wokwi.toml 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/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..c6fedc1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "ostream": "cpp", + "font_5x7,cpp": "cpp" + } +} \ No newline at end of file diff --git a/diagram.json b/diagram.json new file mode 100644 index 0000000..18ebf5f --- /dev/null +++ b/diagram.json @@ -0,0 +1,26 @@ +{ + "version": 1, + "author": "RGB Matrix Pico W Project", + "editor": "wokwi", + "parts": [ + { + "type": "board-pi-pico-w", + "id": "picow", + "top": 1014.35, + "left": 3.55 + }, + { + "type": "wokwi-led-matrix", + "id": "matrix", + "top": -617.6, + "left": 1.1, + "attrs": { "rows": "64", "cols": "64", "pixels": "[]" } + } + ], + "connections": [ + ["matrix:VDD", "picow:VBUS", "red", ["v96", "h-91.4"]], + ["matrix:VSS", "picow:GND.8", "black", ["v0"]], + ["matrix:DIN", "picow:GP28", "green", ["v0"]] + ], + "dependencies": {} +} 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/lib/BlinkLed/library.json b/lib/BlinkLed/library.json new file mode 100644 index 0000000..7b6fd93 --- /dev/null +++ b/lib/BlinkLed/library.json @@ -0,0 +1,7 @@ +{ + "name": "BlinkLed", + "version": "1.0.0", + "description": "A simple LED control library with internal LED helper.", + "authors": [{ "name": "TiiJay14" }], + "frameworks": "arduino" +} diff --git a/lib/BlinkLed/src/BlinkInternLed.h b/lib/BlinkLed/src/BlinkInternLed.h new file mode 100644 index 0000000..f9f7f6a --- /dev/null +++ b/lib/BlinkLed/src/BlinkInternLed.h @@ -0,0 +1,16 @@ +#ifndef BLINKINTERNLED +#define BLINKINTERNLED + +#include +#include "BlinkLed.h" + +class BlinkInternLed : public BlinkLed +{ +private: + /* data */ +public: + BlinkInternLed() : BlinkLed(LED_BUILTIN) {} + ~BlinkInternLed() {} +}; + +#endif diff --git a/lib/BlinkLed/src/BlinkLed.cpp b/lib/BlinkLed/src/BlinkLed.cpp new file mode 100644 index 0000000..504fcb0 --- /dev/null +++ b/lib/BlinkLed/src/BlinkLed.cpp @@ -0,0 +1,25 @@ +#include "BlinkLed.h" + +BlinkLed::BlinkLed(byte pin) +{ + BlinkLed(); + _pin = pin; + pinMode(_pin, OUTPUT); +} + +String BlinkLed::ledStatus() +{ + return _ledStatus == HIGH ? "HIGH" : "LOW"; +} + +void BlinkLed::on() +{ + _ledStatus = HIGH; + digitalWrite(_pin, _ledStatus); +} + +void BlinkLed::off() +{ + _ledStatus = LOW; + digitalWrite(_pin, _ledStatus); +} diff --git a/lib/BlinkLed/src/BlinkLed.h b/lib/BlinkLed/src/BlinkLed.h new file mode 100644 index 0000000..698db4b --- /dev/null +++ b/lib/BlinkLed/src/BlinkLed.h @@ -0,0 +1,24 @@ +#ifndef BLINKLED +#define BLINKLED + +#include + +class BlinkLed +{ +private: + PinStatus _ledStatus; + byte _pin; + /* data */ + BlinkLed() { _ledStatus = LOW; } + +public: + BlinkLed(byte pin); + ~BlinkLed() {} + + void on(); + void off(); + + String ledStatus(); +}; + +#endif diff --git a/lib/Fonts/library.json b/lib/Fonts/library.json new file mode 100644 index 0000000..7b6fd93 --- /dev/null +++ b/lib/Fonts/library.json @@ -0,0 +1,7 @@ +{ + "name": "BlinkLed", + "version": "1.0.0", + "description": "A simple LED control library with internal LED helper.", + "authors": [{ "name": "TiiJay14" }], + "frameworks": "arduino" +} diff --git a/lib/Fonts/src/font_5x7.cpp b/lib/Fonts/src/font_5x7.cpp new file mode 100644 index 0000000..9349db0 --- /dev/null +++ b/lib/Fonts/src/font_5x7.cpp @@ -0,0 +1,59 @@ +#include "font_5x7.h" + +// Function to get font data for a character +const uint8_t *getFontChar(char c) +{ + for (int i = 0; i < sizeof(font_chars) - 1; i++) + { + if (font_chars[i] == c) + { + return font_5x7[i]; + } + } + return font_5x7[52]; // Return space if not found (index of ' ') +} + +// Function to get character width +uint8_t getCharWidth(char c) +{ + switch (c) + { + case 'I': + case '!': + case '.': + case ':': + case ';': + case '\'': + case '|': + return 1; + case 'i': + case ' ': + return 2; + case 'J': + case 'j': + case 'l': + case '(': + case ')': + case '[': + case ']': + case '{': + case '}': + // Nachher (Korrektur): + case 176: // '°' als ASCII Code + case 149: // '•' als ASCII Code + return 3; + case 'a': + case 'c': + case 'e': + case 'f': + case 'k': + case 's': + case 't': + case '<': + case '>': + case '`': + return 4; + default: + return 5; + } +} diff --git a/lib/Fonts/src/font_5x7.h b/lib/Fonts/src/font_5x7.h new file mode 100644 index 0000000..c82a774 --- /dev/null +++ b/lib/Fonts/src/font_5x7.h @@ -0,0 +1,124 @@ +#ifndef FONT_5X7_H +#define FONT_5X7_H + +#include + +// 5x7 Font mit optimierten Zeichenbreiten +const uint8_t font_5x7[][7] = { + // Uppercase letters (A-Z) + {0x0E, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11}, // 'A' Width: 5 + {0x1E, 0x11, 0x11, 0x1E, 0x11, 0x11, 0x1E}, // 'B' Width: 5 + {0x0E, 0x11, 0x10, 0x10, 0x10, 0x11, 0x0E}, // 'C' Width: 5 + {0x1E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1E}, // 'D' Width: 5 + {0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x1F}, // 'E' Width: 5 + {0x1F, 0x10, 0x10, 0x1E, 0x10, 0x10, 0x10}, // 'F' Width: 5 + {0x0E, 0x11, 0x10, 0x13, 0x11, 0x11, 0x0F}, // 'G' Width: 5 + {0x11, 0x11, 0x11, 0x1F, 0x11, 0x11, 0x11}, // 'H' Width: 5 + {0x07, 0x02, 0x02, 0x02, 0x02, 0x02, 0x07}, // 'I' Width: 3 + {0x07, 0x02, 0x02, 0x02, 0x02, 0x12, 0x0C}, // 'J' Width: 4 + {0x11, 0x12, 0x14, 0x18, 0x14, 0x12, 0x11}, // 'K' Width: 5 + {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F}, // 'L' Width: 5 + {0x11, 0x1B, 0x15, 0x15, 0x11, 0x11, 0x11}, // 'M' Width: 5 + {0x11, 0x19, 0x19, 0x15, 0x13, 0x13, 0x11}, // 'N' Width: 5 + {0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E}, // 'O' Width: 5 + {0x1E, 0x11, 0x11, 0x1E, 0x10, 0x10, 0x10}, // 'P' Width: 5 + {0x0E, 0x11, 0x11, 0x11, 0x15, 0x12, 0x0D}, // 'Q' Width: 5 + {0x1E, 0x11, 0x11, 0x1E, 0x14, 0x12, 0x11}, // 'R' Width: 5 + {0x0F, 0x10, 0x10, 0x0E, 0x01, 0x01, 0x1E}, // 'S' Width: 5 + {0x1F, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04}, // 'T' Width: 5 + {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x0E}, // 'U' Width: 5 + {0x11, 0x11, 0x11, 0x11, 0x11, 0x0A, 0x04}, // 'V' Width: 5 + {0x11, 0x11, 0x11, 0x15, 0x15, 0x15, 0x0A}, // 'W' Width: 5 + {0x11, 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x11}, // 'X' Width: 5 + {0x11, 0x11, 0x0A, 0x04, 0x04, 0x04, 0x04}, // 'Y' Width: 5 + {0x1F, 0x01, 0x02, 0x04, 0x08, 0x10, 0x1F}, // 'Z' Width: 5 + + // Lowercase letters (a-z) + {0x00, 0x00, 0x0E, 0x01, 0x0F, 0x11, 0x0F}, // 'a' Width: 4 + {0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x1E}, // 'b' Width: 5 + {0x00, 0x00, 0x0E, 0x11, 0x10, 0x11, 0x0E}, // 'c' Width: 4 + {0x01, 0x01, 0x0D, 0x13, 0x11, 0x11, 0x0F}, // 'd' Width: 5 + {0x00, 0x00, 0x0E, 0x11, 0x1F, 0x10, 0x0E}, // 'e' Width: 4 + {0x06, 0x09, 0x08, 0x1C, 0x08, 0x08, 0x08}, // 'f' Width: 4 + {0x00, 0x0F, 0x11, 0x11, 0x0F, 0x01, 0x0E}, // 'g' Width: 5 + {0x10, 0x10, 0x16, 0x19, 0x11, 0x11, 0x11}, // 'h' Width: 5 + {0x00, 0x02, 0x00, 0x06, 0x02, 0x02, 0x07}, // 'i' Width: 2 + {0x00, 0x02, 0x00, 0x06, 0x02, 0x12, 0x0C}, // 'j' Width: 3 + {0x10, 0x10, 0x12, 0x14, 0x18, 0x14, 0x12}, // 'k' Width: 4 + {0x06, 0x02, 0x02, 0x02, 0x02, 0x02, 0x07}, // 'l' Width: 3 + {0x00, 0x00, 0x1A, 0x15, 0x15, 0x15, 0x15}, // 'm' Width: 5 + {0x00, 0x00, 0x16, 0x19, 0x11, 0x11, 0x11}, // 'n' Width: 5 + {0x00, 0x00, 0x0E, 0x11, 0x11, 0x11, 0x0E}, // 'o' Width: 4 + {0x00, 0x00, 0x1E, 0x11, 0x1E, 0x10, 0x10}, // 'p' Width: 5 + {0x00, 0x00, 0x0D, 0x13, 0x0F, 0x01, 0x01}, // 'q' Width: 5 + {0x00, 0x00, 0x16, 0x19, 0x10, 0x10, 0x10}, // 'r' Width: 5 + {0x00, 0x00, 0x0E, 0x10, 0x0E, 0x01, 0x1E}, // 's' Width: 4 + {0x08, 0x08, 0x1C, 0x08, 0x08, 0x09, 0x06}, // 't' Width: 4 + {0x00, 0x00, 0x11, 0x11, 0x11, 0x13, 0x0D}, // 'u' Width: 5 + {0x00, 0x00, 0x11, 0x11, 0x11, 0x0A, 0x04}, // 'v' Width: 5 + {0x00, 0x00, 0x11, 0x11, 0x15, 0x15, 0x0A}, // 'w' Width: 5 + {0x00, 0x00, 0x11, 0x0A, 0x04, 0x0A, 0x11}, // 'x' Width: 5 + {0x00, 0x00, 0x11, 0x11, 0x0F, 0x01, 0x0E}, // 'y' Width: 5 + {0x00, 0x00, 0x1F, 0x02, 0x04, 0x08, 0x1F}, // 'z' Width: 5 + + // Numbers (0-9) + {0x0E, 0x11, 0x13, 0x15, 0x19, 0x11, 0x0E}, // '0' Width: 5 + {0x02, 0x06, 0x02, 0x02, 0x02, 0x02, 0x07}, // '1' Width: 3 + {0x0E, 0x11, 0x01, 0x02, 0x04, 0x08, 0x1F}, // '2' Width: 5 + {0x1F, 0x02, 0x04, 0x02, 0x01, 0x11, 0x0E}, // '3' Width: 5 + {0x02, 0x06, 0x0A, 0x12, 0x1F, 0x02, 0x02}, // '4' Width: 5 + {0x1F, 0x10, 0x1E, 0x01, 0x01, 0x11, 0x0E}, // '5' Width: 5 + {0x06, 0x08, 0x10, 0x1E, 0x11, 0x11, 0x0E}, // '6' Width: 5 + {0x1F, 0x01, 0x02, 0x04, 0x08, 0x08, 0x08}, // '7' Width: 5 + {0x0E, 0x11, 0x11, 0x0E, 0x11, 0x11, 0x0E}, // '8' Width: 5 + {0x0E, 0x11, 0x11, 0x0F, 0x01, 0x02, 0x0C}, // '9' Width: 5 + + // Punctuation and symbols + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // ' ' Width: 2 + {0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x01}, // '!' Width: 1 + {0x0E, 0x11, 0x02, 0x04, 0x04, 0x00, 0x04}, // '?' Width: 5 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, // '.' Width: 1 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02}, // ',' Width: 1 + {0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00}, // ':' Width: 1 + {0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x02}, // ';' Width: 1 + {0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}, // "'" Width: 1 + {0x05, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00}, // '"' Width: 3 + {0x00, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00}, // '-' Width: 5 + {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F}, // '_' Width: 5 + {0x00, 0x04, 0x04, 0x1F, 0x04, 0x04, 0x00}, // '+' Width: 5 + {0x00, 0x00, 0x1F, 0x00, 0x1F, 0x00, 0x00}, // '=' Width: 5 + {0x00, 0x0A, 0x04, 0x1F, 0x04, 0x0A, 0x00}, // '*' Width: 5 + {0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x00}, // '/' Width: 5 + {0x00, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00}, // '\\' Width: 5 + {0x01, 0x02, 0x04, 0x04, 0x04, 0x02, 0x01}, // '(' Width: 3 + {0x04, 0x02, 0x01, 0x01, 0x01, 0x02, 0x04}, // ')' Width: 3 + {0x07, 0x04, 0x04, 0x04, 0x04, 0x04, 0x07}, // '[' Width: 3 + {0x07, 0x01, 0x01, 0x01, 0x01, 0x01, 0x07}, // ']' Width: 3 + {0x03, 0x02, 0x02, 0x04, 0x02, 0x02, 0x03}, // '{' Width: 3 + {0x06, 0x02, 0x02, 0x01, 0x02, 0x02, 0x06}, // '}' Width: 3 + {0x00, 0x01, 0x02, 0x04, 0x02, 0x01, 0x00}, // '<' Width: 4 + {0x00, 0x04, 0x02, 0x01, 0x02, 0x04, 0x00}, // '>' Width: 4 + {0x0E, 0x11, 0x17, 0x15, 0x17, 0x10, 0x0E}, // '@' Width: 5 + {0x0A, 0x0A, 0x1F, 0x0A, 0x1F, 0x0A, 0x0A}, // '#' Width: 5 + {0x04, 0x0F, 0x14, 0x0E, 0x05, 0x1E, 0x04}, // '$' Width: 5 + {0x18, 0x19, 0x02, 0x04, 0x08, 0x13, 0x03}, // '%' Width: 5 + {0x0C, 0x12, 0x14, 0x08, 0x15, 0x12, 0x0D}, // '&' Width: 5 + {0x04, 0x0A, 0x11, 0x00, 0x00, 0x00, 0x00}, // '^' Width: 5 + {0x00, 0x00, 0x00, 0x0D, 0x12, 0x00, 0x00}, // '~' Width: 5 + + // Special characters + {0x07, 0x05, 0x07, 0x00, 0x00, 0x00, 0x00}, // '°' Width: 3 + {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}, // '|' Width: 1 + {0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00}, // '`' Width: 2 + {0x0F, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D, 0x0D}, // '¶' Width: 5 + {0x00, 0x00, 0x02, 0x07, 0x02, 0x00, 0x00} // '•' Width: 3 +}; + +// Character mapping +const char font_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !?.,:;'\"-_+=*/\\()[]{}<>@#$%&^~°|`¶•"; + +// Declarations only +const uint8_t *getFontChar(char c); +uint8_t getCharWidth(char c); + +#endif \ No newline at end of file diff --git a/lib/LedMatrix/library.json b/lib/LedMatrix/library.json new file mode 100644 index 0000000..7b6fd93 --- /dev/null +++ b/lib/LedMatrix/library.json @@ -0,0 +1,7 @@ +{ + "name": "BlinkLed", + "version": "1.0.0", + "description": "A simple LED control library with internal LED helper.", + "authors": [{ "name": "TiiJay14" }], + "frameworks": "arduino" +} diff --git a/lib/LedMatrix/src/LedMatrix.cpp b/lib/LedMatrix/src/LedMatrix.cpp new file mode 100644 index 0000000..3761d31 --- /dev/null +++ b/lib/LedMatrix/src/LedMatrix.cpp @@ -0,0 +1,11 @@ +#include "LedMatrix.h" + +LedMatrix::LedMatrix(uint8_t h, uint8_t w) + : height(h), width(w), num_leds(h * w), leds(num_leds) +{ + addLeds(leds.data(), num_leds); +} + +LedMatrix::~LedMatrix() +{ +} \ No newline at end of file diff --git a/lib/LedMatrix/src/LedMatrix.h b/lib/LedMatrix/src/LedMatrix.h new file mode 100644 index 0000000..e68e4cc --- /dev/null +++ b/lib/LedMatrix/src/LedMatrix.h @@ -0,0 +1,64 @@ +#ifndef LEDMATRIX +#define LEDMATRIX + +using namespace std; + +#include +#include +#include + +#include + +class LedMatrix : public CFastLED +{ +private: + uint8_t height; + uint8_t width; + + static const uint8_t MATRIX_PIN = 28; + uint16_t num_leds; // default 64x64 = 4096 LEDs + vector leds; // Automatic memory management + +public: + LedMatrix(uint8_t h = 64, uint8_t w = 64); + + ~LedMatrix(); + + void drawPixel(int x, int y, CRGB color) + { + if (x >= 0 && x < 64 && y >= 0 && y < 64) + { + int index = y * 64 + x; // Row-major order + leds[index] = color; + } + } + + void drawChar(int x, int y, char c, CRGB color) + { + const uint8_t *fontData = getFontChar(c); + for (int row = 0; row < 7; row++) + { + uint8_t line = fontData[row]; + for (int col = 0; col < 5; col++) + { + if (line & (1 << (4 - col))) + { + drawPixel(x + col, y + row, color); + } + } + } + } + + // Draw text string + void drawText(int x, int y, const char *text, CRGB color) + { + int cursorX = x; + for (int i = 0; text[i] != '\0'; i++) + { + drawChar(cursorX, y, text[i], color); + cursorX += 6; // 5 pixels width + 1 pixel spacing + } + } +}; + +#endif \ No newline at end of file diff --git a/lib/MyClass/library.json b/lib/MyClass/library.json new file mode 100644 index 0000000..7b6fd93 --- /dev/null +++ b/lib/MyClass/library.json @@ -0,0 +1,7 @@ +{ + "name": "BlinkLed", + "version": "1.0.0", + "description": "A simple LED control library with internal LED helper.", + "authors": [{ "name": "TiiJay14" }], + "frameworks": "arduino" +} diff --git a/lib/MyClass/src/MyClass.cpp b/lib/MyClass/src/MyClass.cpp new file mode 100644 index 0000000..906a19f --- /dev/null +++ b/lib/MyClass/src/MyClass.cpp @@ -0,0 +1,18 @@ +#include "MyClass.h" + +MyClass::MyClass() : myNum(0), myString("Default") +{ +} + +MyClass::MyClass(int num, const String &str) + : myNum(num), myString(str) +{ +} + +void MyClass::display() +{ + Serial.print("Number: "); + Serial.print(myNum); + Serial.print(", String: "); + Serial.println(myString); +} \ No newline at end of file diff --git a/lib/MyClass/src/MyClass.h b/lib/MyClass/src/MyClass.h new file mode 100644 index 0000000..66a5dda --- /dev/null +++ b/lib/MyClass/src/MyClass.h @@ -0,0 +1,16 @@ +#ifndef MYCLASS_H +#define MYCLASS_H + +#include // Required for String type + +class MyClass { + public: + int myNum; + String myString; // Arduino String + + MyClass(); + MyClass(int num, const String& str); + void display(); +}; + +#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..c729259 --- /dev/null +++ b/platformio.ini @@ -0,0 +1,22 @@ +; 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:rpipicow] +platform = raspberrypi +board = rpipicow +framework = arduino +monitor_speed = 115200 +build_flags = + -D PICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 + +lib_deps = fastled/FastLED@^3.10.3 + +; Add this to see build flags during compilation +; build_flags = -v \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..5611d0f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,80 @@ +#include +#include +#include +#include +#include + +LedMatrix matrix; + +void printCharMatrixSimple(char c) +{ + const uint8_t *fontData = getFontChar(c); + + Serial.println(); + Serial.print("'"); + Serial.print(c); + Serial.println("':"); + + String mtrx = ""; + for (int row = 0; row < 7; row++) + { + uint8_t line = fontData[row]; + for (int col = 0; col < 5; col++) + { + if (line & (1 << (4 - col))) + { + mtrx += "•"; + Serial.print("#"); // Einfaches # für Pixel + } + else + { + mtrx += "."; + Serial.print("."); // Punkt für leere Pixel + } + } + mtrx += "\n\r"; + Serial.println(); + } + Serial.println(mtrx); +} + +void playWithBlinkLed() +{ + BlinkInternLed internLed = BlinkInternLed(); + String led_status = internLed.ledStatus(); + Serial.println("PinStatus: " + led_status); + + internLed.on(); + delay(200); + led_status = internLed.ledStatus(); + Serial.println("PinStatus: " + led_status); + + internLed.off(); + delay(200); + led_status = internLed.ledStatus(); + Serial.println("PinStatus: " + led_status); +} + +void setup() +{ + matrix.setBrightness(255); + + matrix.clear(); + matrix.show(); + + // Draw static "HELLO WORLD" + matrix.drawText(1, 1, "Hello", CRGB::Red); + matrix.drawText(35, 1, "World", CRGB::Blue); + matrix.drawText(1, 20, "<°|`¶>", CRGB::Yellow); + matrix.drawText(1, 30, "Bottom", CRGB::Yellow); + matrix.show(); + + // printCharMatrixSimple('S'); + + // playWithBlinkLed(); +} + +void loop() +{ + delay(1000); +} \ No newline at end of file diff --git a/src/main___.cpp b/src/main___.cpp new file mode 100644 index 0000000..8227df6 --- /dev/null +++ b/src/main___.cpp @@ -0,0 +1,94 @@ +#ifdef DO_NOT_USE_MAIN___ +#include +#include +#include + +#include +#include +// #include + +#include "MyClass.h" + +// LED pin definitions +#define LED_ONBOARD LED_BUILTIN + +// Matrix setup +#define MATRIX_PIN 28 +#define MATRIX_WIDTH 64 +#define MATRIX_HEIGHT 64 + +// Adafruit NeoMatrix initialisieren +Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix( + MATRIX_WIDTH, MATRIX_HEIGHT, MATRIX_PIN, + NEO_MATRIX_TOP + NEO_MATRIX_LEFT + + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG, + NEO_GRB + NEO_KHZ800); + +int textX = matrix.width(); +int textMin = 0; + +void connect_wifi() +{ + // For Wokwi simulation - use simulated WiFi + Serial.println("Connecting to WiFi..."); + + // In Wokwi, WiFi connects automatically in simulation + WiFi.begin("Wokwi-GUEST", ""); // Wokwi's simulated WiFi + while (WiFi.status() != WL_CONNECTED) + { + delay(250); + Serial.print("."); + } + Serial.println("\nConnected to WiFi!"); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); +} + +void setupLEDMatrix() +{ + // Matrix initialisieren + matrix.begin(); + + matrix.setBrightness(200); + matrix.fillScreen(0); + matrix.setCursor(18, 12); + matrix.setTextColor(matrix.Color(0, 255, 0)); + matrix.print("HELLO"); + matrix.show(); + Serial.println("Adafruit NeoMatrix ready - Showing 'Hello World'"); +} + +void setup___() +{ + Serial.begin(115200); + delay(100); + + connect_wifi(); + + MyClass myClassObj; // Create an object of MyClass + + // Access attributes and set values + myClassObj.myNum = 15; + myClassObj.myString = "Some text"; + + pinMode(LED_ONBOARD, OUTPUT); + Serial.println("Blink example started!"); + myClassObj.display(); + + setupLEDMatrix(); +} + +void loop___() +{ + + // Turn LED on + digitalWrite(LED_ONBOARD, HIGH); + Serial.println("LED ON"); + delay(1000); + + // Turn LED off + digitalWrite(LED_ONBOARD, LOW); + Serial.println("LED OFF"); + delay(1000); +} +#endif \ 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..183e193 --- /dev/null +++ b/wokwi.toml @@ -0,0 +1,6 @@ +[wokwi] +version = 1 +firmware = ".pio/build/rpipicow/firmware.uf2" + +rfc2217ServerPort = 4000 +gdbServerPort = 3333 \ No newline at end of file