import initial

This commit is contained in:
Julien Cabillot 2017-07-31 18:05:31 +02:00 committed by Cabillot Julien
commit 41ab2ebf0d
6 changed files with 169 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pioenvs
.piolibdeps
.clang_complete
.gcc-flags.json
.travis.yml

36
lib/readme.txt Normal file
View File

@ -0,0 +1,36 @@
This directory is intended for the project specific (private) libraries.
PlatformIO will compile them to static libraries and link to executable file.
The source code of each library should be placed in separate directory, like
"lib/private_lib/[here are source files]".
For example, see how can be organized `Foo` and `Bar` libraries:
|--lib
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |- readme.txt --> THIS FILE
|- platformio.ini
|--src
|- main.c
Then in `src/main.c` you should use:
#include <Foo.h>
#include <Bar.h>
// rest H/C/CPP code
PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.
More information about PlatformIO Library Dependency Finder
- http://docs.platformio.org/page/librarymanager/ldf.html

17
platformio.ini Normal file
View File

@ -0,0 +1,17 @@
; 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
; http://docs.platformio.org/page/projectconf.html
[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
[platformio]
lib_dir=~/Arduino/libraries

85
src/ledmask.cpp Normal file
View File

@ -0,0 +1,85 @@
#include "Arduino.h"
#include <FastLED.h>
#include "ledmask.h"
/*
TODO: à adapter
LED attached from pin 13 to ground
pushbutton attached to pin 2 from +5V
10K resistor attached to pin 2 from ground
*/
/** FIRE2012 **/
void Fire2012()
{
// Array of temperature readings at each simulation cell
static byte heat[LED_NUM];
// Step 1. Cool down every cell a little
for( int i = 0; i < LED_NUM; i++) {
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / LED_NUM) + 2));
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( int k= LED_NUM - 1; k >= 2; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
}
// Step 3. Randomly ignite new 'sparks' of heat near the bottom
if( random8() < SPARKING ) {
int y = random8(7);
heat[y] = qadd8( heat[y], random8(160,255) );
}
// Step 4. Map from heat cells to LED colors
for( int j = 0; j < LED_NUM; j++) {
CRGB color = HeatColor( heat[j]);
int pixelnumber;
if( gReverseDirection ) {
pixelnumber = (LED_NUM - 1) - j;
} else {
pixelnumber = j;
}
leds[pixelnumber] = color;
}
}
void setup() {
Serial.begin(SERIAL_SPEED);
Serial.println("\nresetting");
/** BOUTON **/
// powering button
pinMode(POWERPIN, OUTPUT);
digitalWrite(POWERPIN, HIGH);
// initialize the pushbutton pin as an input:
pinMode(BUTTON_PIN, INPUT);
buttonState = 0;
delay(200);
/** LEDS **/
LEDS.addLeds<LED_CHIPSET,LED_PIN, LED_COLOR_ORDER>(leds, LED_NUM).setCorrection(TypicalSMD5050);
FastLED.setBrightness(LED_BRIGHTNESS);
}
void loop() {
/** BOUTON **/
EVERY_N_MILLISECONDS(500) {
buttonState = digitalRead(BUTTON_PIN);
if (buttonState == HIGH) {
Serial.println("HIGH");
} else {
Serial.println("LOW");
}
}
// Add entropy to random number generator; we use a lot of it.
random16_add_entropy(random());
Fire2012(); // run simulation frame
FastLED.show(); // display this frame
FastLED.delay(1000 / LED_FPS);
}

26
src/ledmask.h Normal file
View File

@ -0,0 +1,26 @@
#define SERIAL_SPEED 115200
/** BOUTON **/
#define POWERPIN 2
#define BUTTON_PIN 8
int buttonState;
/** LED **/
#define LED_PIN 5
#define LED_CHIPSET WS2812B
#define LED_COLOR_ORDER GRB
#define LED_NUM 30
#define LED_BRIGHTNESS 200
#define LED_FPS 60
const bool gReverseDirection = false;
CRGB leds[LED_NUM];
/** FIRE2012 **/
#define COOLING 55
#define SPARKING 120
void setup();
void loop();
void Fire2012();

0
src/ledmask.ino Normal file
View File