generated from atopile/project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from mawildoer/mawildoer/add-firmware
Add firwmare!
- Loading branch information
Showing
5 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,7 @@ venv/ | |
|
||
# IDEs | ||
.vscode/ | ||
|
||
|
||
# PlatformIO | ||
.pio/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |