diff --git a/.gitignore b/.gitignore index 4ff02fb..4c90e58 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,7 @@ venv/ # IDEs .vscode/ + + +# PlatformIO +.pio/ diff --git a/firmware/include/README b/firmware/include/README new file mode 100644 index 0000000..194dcd4 --- /dev/null +++ b/firmware/include/README @@ -0,0 +1,39 @@ + +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 usual convention is to give header files names that end with `.h'. +It is most portable to use only letters, digits, dashes, and underscores in +header file names, and at most one dot. + +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/firmware/src/main.cpp b/firmware/src/main.cpp new file mode 100644 index 0000000..0af183d --- /dev/null +++ b/firmware/src/main.cpp @@ -0,0 +1,97 @@ +#include + +#define WIDTH 9 +#define HEIGHT 9 +#define NUM_LEDS (WIDTH * HEIGHT) +#define DATA_PIN 16 +#define MAX_BRIGHTNESS 100 +#define LED_TYPE WS2812B +#define COLOR_ORDER GRB +CRGB leds[NUM_LEDS]; +char buffer[100]; + +#define ATOPILE_ORANGE 0xFFFF00 + +const bool imagePattern[HEIGHT][WIDTH] = { + {false, true, false, true, true, false, true, true, true}, + {false, false, false, false, true, false, false, false, true}, + {false, true, true, false, true, true, true, false, true}, + {false, false, true, true, false, false, true, false, false}, + {true, true, false, true, true, false, true, true, true}, + {false, true, false, false, true, false, false, false, true}, + {false, true, true, false, true, true, true, false, true}, + {false, false, true, true, false, false, false, false, true}, + {true, true, false, true, true, true, true, true, true}}; + +uint16_t XY(uint8_t x, uint8_t y) +{ + return (y * WIDTH) + x; +} + +void displayImage() +{ + for (int row = 0; row < HEIGHT; row++) + { + for (int col = 0; col < WIDTH; col++) + { + leds[XY(col, row)] = imagePattern[row][col] ? ATOPILE_ORANGE : false; + } + } + FastLED.show(); +} + +void setup() +{ + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(MAX_BRIGHTNESS); + displayImage(); + Serial.begin(115200); + pinMode(0, INPUT); +} + +void wavePulse() +{ + static long startTime = millis(); + long currentTime = millis(); + float waveSpeed = 0.25; // controls the speed of the wave + + for (int row = 0; row < HEIGHT; row++) + { + for (int col = 0; col < WIDTH; col++) + { + if (imagePattern[row][col]) + { + // Calculate the distance from the center of the wave + float distance = sqrt(sq(row - HEIGHT / 2.0) + sq(col - WIDTH / 2.0)); + // Calculate the wave pattern based on the distance + float wavePattern = sin(distance * waveSpeed - (currentTime - startTime) * 0.002); + // Map the wave pattern to a brightness value + uint8_t brightness = map((wavePattern + 1) * 127.5, 0, 255, 0, MAX_BRIGHTNESS); + // Set the LED color with the new brightness value + leds[XY(col, row)] = CHSV(23, 255, brightness); + // sprintf(buffer, "row: %d, col: %d, distance: %f, wavePattern: %f, brightness: %d\n", row, col, distance, wavePattern, brightness); + } + else + { + leds[XY(col, row)] = false; + // sprintf(buffer, "row: %d, col: %d\n", row, col); + } + // Serial.print(buffer); + } + // Serial.println(); + } + // Serial.println(); + // Serial.println(); + // Serial.println(); + FastLED.show(); + delay(15); // You can adjust this for a faster or slower wave +} + +void loop() +{ + wavePulse(); + if (millis() > 3600 * 1000) + { + FastLED.setBrightness(0); + } +} diff --git a/firmware/test/README b/firmware/test/README new file mode 100644 index 0000000..9b1e87b --- /dev/null +++ b/firmware/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/platformio.ini b/platformio.ini new file mode 100644 index 0000000..abda3db --- /dev/null +++ b/platformio.ini @@ -0,0 +1,23 @@ +; 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 + +[platformio] +include_dir = firmware/include +lib_dir = firmware/lib +src_dir = firmware/src +test_dir = firmware/test + +[env:pico] +platform = raspberrypi +board = pico +framework = arduino +monitor_dtr = 1 +monitor_speed = 115200 +lib_deps = fastled/FastLED@^3.6.0