commit 41ab2ebf0d44c6245acf39d117ebe1f9905bddb4 Author: Julien Cabillot Date: Mon Jul 31 18:05:31 2017 +0200 import initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..967989d --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json +.travis.yml diff --git a/lib/readme.txt b/lib/readme.txt new file mode 100644 index 0000000..dbadc3d --- /dev/null +++ b/lib/readme.txt @@ -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 +#include + +// 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 diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..dbdbbe6 --- /dev/null +++ b/platformio.ini @@ -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 diff --git a/src/ledmask.cpp b/src/ledmask.cpp new file mode 100644 index 0000000..de2b1f3 --- /dev/null +++ b/src/ledmask.cpp @@ -0,0 +1,85 @@ +#include "Arduino.h" + +#include + +#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(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); +} diff --git a/src/ledmask.h b/src/ledmask.h new file mode 100644 index 0000000..fd6640b --- /dev/null +++ b/src/ledmask.h @@ -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(); diff --git a/src/ledmask.ino b/src/ledmask.ino new file mode 100644 index 0000000..e69de29