Skip to content

Commit a54180a

Browse files
committed
Initial commit
0 parents  commit a54180a

File tree

9 files changed

+249
-0
lines changed

9 files changed

+249
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"platformio.platformio-ide"
6+
]
7+
}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Fire
2+

include/README

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

platformio.ini

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:adafruit_matrix_portal_m4]
12+
platform = atmelsam
13+
board = adafruit_matrix_portal_m4
14+
framework = arduino
15+
lib_deps =
16+
adafruit/Adafruit Protomatter@^1.0.10
17+
adafruit/Adafruit BusIO@^1.7.1

src/main.cpp

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#include <Arduino.h>
2+
#include <Wire.h>
3+
#include <SPI.h>
4+
#include <Adafruit_Protomatter.h> // For RGB matrix
5+
6+
#define WIDTH 64
7+
#define HEIGHT 32
8+
#define FIRE_WIDTH 32
9+
#define FIRE_HEIGHT 65
10+
#define MAX_FPS 25
11+
12+
// Remaining pins are the same for all matrix sizes. These values
13+
// are for MatrixPortal M4. See "simple" example for other boards.
14+
uint8_t rgbPins[] = {7, 8, 9, 10, 11, 12};
15+
uint8_t addrPins[] = {17, 18, 19, 20};
16+
uint8_t clockPin = 14;
17+
uint8_t latchPin = 15;
18+
uint8_t oePin = 16;
19+
20+
Adafruit_Protomatter matrix(
21+
WIDTH, 6, 1, rgbPins, sizeof(addrPins), addrPins,
22+
clockPin, latchPin, oePin, true);
23+
24+
uint16_t palette[256];
25+
26+
uint8_t fire[FIRE_HEIGHT][FIRE_WIDTH];
27+
28+
uint16_t HSLto565(float H, float S, float V) {
29+
float s = S/100;
30+
float v = V/100;
31+
float C = s*v;
32+
float X = C*(1-abs(fmod(H/60.0, 2)-1));
33+
float m = v-C;
34+
float r,g,b;
35+
36+
if(H >= 0 && H < 60){
37+
r = C,g = X,b = 0;
38+
}
39+
else if(H >= 60 && H < 120){
40+
r = X,g = C,b = 0;
41+
}
42+
else if(H >= 120 && H < 180){
43+
r = 0,g = C,b = X;
44+
}
45+
else if(H >= 180 && H < 240){
46+
r = 0,g = X,b = C;
47+
}
48+
else if(H >= 240 && H < 300){
49+
r = X,g = 0,b = C;
50+
}
51+
else{
52+
r = C,g = 0,b = X;
53+
}
54+
int R = (r+m)*255;
55+
int G = (g+m)*255;
56+
int B = (b+m)*255;
57+
58+
return matrix.color565(R, G, B);
59+
}
60+
61+
void setup() {
62+
// put your setup code here, to run once:
63+
ProtomatterStatus status = matrix.begin();
64+
if(status != PROTOMATTER_OK) {
65+
// DO NOT CONTINUE if matrix setup encountered an error.
66+
for(;;);
67+
}
68+
69+
// Calculate palette
70+
for (int index = 0; index < 128; ++index) {
71+
palette[index] = HSLto565(index / 6, 100, (index * 2.0) * 100 / 256);
72+
}
73+
74+
for (int index = 128; index < 256; ++index) {
75+
palette[index] = HSLto565(index / 6, (384 - index) * 100 / 256, 100);
76+
}
77+
78+
// Clear buffer
79+
for (int y = 0; y < FIRE_HEIGHT; ++y) {
80+
for (int x = 0; x < FIRE_WIDTH; ++x) {
81+
fire[y][x] = 0;
82+
}
83+
}
84+
}
85+
86+
uint32_t prevTime = 0;
87+
88+
void loop() {
89+
uint32_t t;
90+
while(((t = micros()) - prevTime) < (1000000L / MAX_FPS));
91+
prevTime = t;
92+
93+
// Randomize bottom row
94+
for (int x = 0; x < FIRE_WIDTH; ++x) {
95+
int n = random(4) + 1;
96+
fire[FIRE_HEIGHT - 1][x] = n * n * n * n - 1;
97+
}
98+
99+
//do the fire calculations for every pixel, from top to bottom
100+
for(int y = 0; y < FIRE_HEIGHT - 1; y++)
101+
for(int x = 0; x < FIRE_WIDTH; x++)
102+
{
103+
fire[y][x] =
104+
((fire[(y + 1) % FIRE_HEIGHT][(x - 1 + FIRE_WIDTH) % FIRE_WIDTH]
105+
+ fire[(y + 1) % FIRE_HEIGHT][(x) % FIRE_WIDTH]
106+
+ fire[(y + 1) % FIRE_HEIGHT][(x + 1) % FIRE_WIDTH]
107+
+ fire[(y + 2) % FIRE_HEIGHT][(x) % FIRE_WIDTH])
108+
* 32) / 132;
109+
}
110+
111+
// Draw fire
112+
for (int y = 0; y < matrix.width(); ++y) {
113+
for (int x = 0; x < matrix.height(); ++x) {
114+
// Things are rotated 90 CCW
115+
matrix.drawPixel(y, x, palette[fire[y][x]]);
116+
}
117+
}
118+
119+
matrix.show();
120+
}

test/README

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
This directory is intended for PlatformIO Unit Testing and project tests.
3+
4+
Unit Testing is a software testing method by which individual units of
5+
source code, sets of one or more MCU program modules together with associated
6+
control data, usage procedures, and operating procedures, are tested to
7+
determine whether they are fit for use. Unit testing finds problems early
8+
in the development cycle.
9+
10+
More information about PlatformIO Unit Testing:
11+
- https://docs.platformio.org/page/plus/unit-testing.html

0 commit comments

Comments
 (0)