Skip to content

Commit

Permalink
Merge pull request #6 from mawildoer/mawildoer/add-firmware
Browse files Browse the repository at this point in the history
Add firwmare!
  • Loading branch information
mawildoer authored Mar 25, 2024
2 parents e5d8617 + 4a7a1ec commit 52e6c86
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ venv/

# IDEs
.vscode/


# PlatformIO
.pio/
39 changes: 39 additions & 0 deletions firmware/include/README
Original file line number Diff line number Diff line change
@@ -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
97 changes: 97 additions & 0 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include <FastLED.h>

#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<LED_TYPE, DATA_PIN, COLOR_ORDER>(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);
}
}
11 changes: 11 additions & 0 deletions firmware/test/README
Original file line number Diff line number Diff line change
@@ -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
23 changes: 23 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 52e6c86

Please sign in to comment.