add more modes and pushbuttonselector
This commit is contained in:
parent
13b4aa1d4b
commit
0dc442b446
2 changed files with 78 additions and 23 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
||||||
.clang_complete
|
.clang_complete
|
||||||
.gcc-flags.json
|
.gcc-flags.json
|
||||||
.ccls
|
.ccls
|
||||||
|
*.swp
|
||||||
|
|
100
src/main.ino
100
src/main.ino
|
@ -9,22 +9,28 @@
|
||||||
|
|
||||||
#define LED_PIN 7
|
#define LED_PIN 7
|
||||||
|
|
||||||
const int mode = 2; // 1 for acceleration, 2 for fire
|
byte mode = 2; // 0 for acceleration, 1 for fire, 2 for waterfall, 3 pride, 4 glitter, 5 off
|
||||||
const int debug = 2;
|
const byte NUM_MODES = 6;
|
||||||
const int STRIPS = 2;
|
const byte debug = 3;
|
||||||
const int NUM_LEDS = 15;
|
const byte STRIPS = 6;
|
||||||
const int FRAMES_PER_SECOND = 30;
|
const byte NUM_LEDS = 10;
|
||||||
|
const byte FRAMES_PER_SECOND = 30;
|
||||||
const float range = 0.5; //accelleration range in g
|
const float range = 0.5; //accelleration range in g
|
||||||
|
|
||||||
const int BRIGHTNESS = 50;
|
const byte BRIGHTNESS = 50;
|
||||||
const int COOLING = 80;
|
const byte COOLING = 80;
|
||||||
const int SPARKING = 50;
|
const byte SPARKING = 50;
|
||||||
|
uint8_t gHue = 0;
|
||||||
|
|
||||||
|
|
||||||
float accelerationHistory [STRIPS];
|
float accelerationHistory [STRIPS];
|
||||||
|
|
||||||
MPU6050 mpu(Wire);
|
MPU6050 mpu(Wire);
|
||||||
CRGB leds[NUM_LEDS * STRIPS];
|
CRGB leds[NUM_LEDS * STRIPS];
|
||||||
CRGBPalette16 gPal;
|
CRGBPalette16 gPal;
|
||||||
|
CRGB flagcolors[6] = {CRGB::Red, CRGB::DarkOrange, CRGB::Yellow, CRGB::DarkGreen, CRGB::Blue, CRGB::DarkViolet};
|
||||||
|
|
||||||
|
const byte modeSwitchPin = 2;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(19200);
|
Serial.begin(19200);
|
||||||
|
@ -32,12 +38,14 @@ void setup() {
|
||||||
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS*STRIPS).setCorrection( TypicalLEDStrip );
|
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS*STRIPS).setCorrection( TypicalLEDStrip );
|
||||||
FastLED.setBrightness( BRIGHTNESS );
|
FastLED.setBrightness( BRIGHTNESS );
|
||||||
|
|
||||||
gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::Yellow, CRGB::White);
|
|
||||||
//gPal = CRGBPalette16( CRGB::Black, CRGB::Blue, CRGB::Aqua, CRGB::White);
|
pinMode(modeSwitchPin, INPUT_PULLUP);
|
||||||
|
attachInterrupt(digitalPinToInterrupt(modeSwitchPin), setMode, RISING);
|
||||||
|
|
||||||
for (int i = 0; i<STRIPS; i++) {
|
for (int i = 0; i<STRIPS; i++) {
|
||||||
accelerationHistory[i] = 1;
|
accelerationHistory[i] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Wire.begin();
|
Wire.begin();
|
||||||
byte status = mpu.begin();
|
byte status = mpu.begin();
|
||||||
|
@ -166,25 +174,71 @@ void calculateFire(int strip){
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawFire(){
|
void drawFire(){
|
||||||
|
if (mode == 1) {
|
||||||
|
gPal = CRGBPalette16( CRGB::Black, CRGB::Red, CRGB::Yellow, CRGB::White);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gPal = CRGBPalette16( CRGB::Black, CRGB::Blue, CRGB::Aqua, CRGB::White);
|
||||||
|
}
|
||||||
for (int i = 0; i < STRIPS; i++){
|
for (int i = 0; i < STRIPS; i++){
|
||||||
calculateFire(i);
|
calculateFire(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void drawPride(){
|
||||||
if (mode == 1) {
|
for (int strip = 0; strip < STRIPS; strip++){
|
||||||
// === Read acceleromter data === //
|
CRGB color = flagcolors[strip];
|
||||||
float accCombined = calculateOrientationData();
|
for( int j = 0; j < NUM_LEDS; j++) {
|
||||||
enableLEDsOnAcceleration(accCombined);
|
int pixelnumber = (strip * NUM_LEDS) + j;
|
||||||
FastLED.show();
|
leds[pixelnumber] = color;
|
||||||
FastLED.delay(1000 / FRAMES_PER_SECOND);
|
}
|
||||||
}
|
|
||||||
else if (mode == 2) {
|
|
||||||
random16_add_entropy( random());
|
|
||||||
drawFire();
|
|
||||||
FastLED.show();
|
|
||||||
FastLED.delay(1000 / FRAMES_PER_SECOND);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawGlitter(){
|
||||||
|
fadeToBlackBy( leds, STRIPS*NUM_LEDS, 10);
|
||||||
|
int pos = random16(STRIPS*NUM_LEDS);
|
||||||
|
leds[pos] += CHSV( gHue + random8(64), 200, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawOff(){
|
||||||
|
fadeToBlackBy( leds, STRIPS*NUM_LEDS, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMode(){
|
||||||
|
mode++;
|
||||||
|
if (mode >= NUM_MODES) {
|
||||||
|
mode = 0;
|
||||||
|
}
|
||||||
|
if (debug <= 3) {
|
||||||
|
Serial.print("Blinkmode:\t");
|
||||||
|
Serial.println(mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
if (mode == 0) {
|
||||||
|
// === Read acceleromter data === //
|
||||||
|
float accCombined = calculateOrientationData();
|
||||||
|
enableLEDsOnAcceleration(accCombined);
|
||||||
|
}
|
||||||
|
else if ((mode == 1) || (mode == 2)) {
|
||||||
|
random16_add_entropy( random());
|
||||||
|
drawFire();
|
||||||
|
}
|
||||||
|
else if (mode == 3) {
|
||||||
|
drawPride();
|
||||||
|
}
|
||||||
|
else if (mode == 4) {
|
||||||
|
drawGlitter();
|
||||||
|
}
|
||||||
|
else if (mode == 5) {
|
||||||
|
drawOff();
|
||||||
|
}
|
||||||
|
FastLED.show();
|
||||||
|
gHue++;
|
||||||
|
FastLED.delay(1000 / FRAMES_PER_SECOND);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue