diff --git a/lib/AcceleratedLED328/lib/Bumps.cpp b/lib/AcceleratedLED328/lib/Bumps.cpp index 8f500f2..8771e11 100644 --- a/lib/AcceleratedLED328/lib/Bumps.cpp +++ b/lib/AcceleratedLED328/lib/Bumps.cpp @@ -1,7 +1,45 @@ #include "Bumps.h" +#include "Range.cpp" Bumps::Bumps(){ + for(uint8_t i=0; i STEP_TIME){ + lastStep = currMillis; + + //int16_t maxAdd = 600; + //uint16_t value = map(currValue.average(), maxValue.min, maxValue.max, -maxAdd, maxAdd ); + uint16_t maxMultiply = 30000; + uint16_t value = map(currValue.average(), maxValue.min, maxValue.max, 1, maxMultiply ); + + currValue.set(INT16_MAX, INT16_MIN); + + this -> pushValue(value); + } + + for(uint8_t i=0; i< strip.stripLength(); i++){ + Pixel* pixel = strip.farPixel(i); + //pixel->hsv.hue += values[i]; + pixel->multiplyValue( values[i] >> 8 ); + } + +} + +void Bumps::pushValue(uint16_t value){ + for(int8_t i= STRIP_LENGTH-2; i>=0; i--){ + values[i+1] = values[i]; + } + values[0] = value; } diff --git a/lib/AcceleratedLED328/lib/Bumps.h b/lib/AcceleratedLED328/lib/Bumps.h index c1356ed..63b3fb2 100644 --- a/lib/AcceleratedLED328/lib/Bumps.h +++ b/lib/AcceleratedLED328/lib/Bumps.h @@ -3,6 +3,7 @@ #include "Arduino.h" #include "Effect.h" +#include "Range.h" class Bumps: public Effect { public: @@ -10,6 +11,12 @@ class Bumps: public Effect { void run(Strip &strip, Data &data); private: + Range maxValue; + Range currValue; + + unsigned long lastStep; + + void pushValue(uint16_t value); uint16_t values[STRIP_LENGTH]; }; diff --git a/lib/AcceleratedLED328/lib/Effects.cpp b/lib/AcceleratedLED328/lib/Effects.cpp index a384180..a3f10e0 100644 --- a/lib/AcceleratedLED328/lib/Effects.cpp +++ b/lib/AcceleratedLED328/lib/Effects.cpp @@ -15,7 +15,7 @@ void Effects::init(){ leftStrip.init(L_DATA, L_CLK); rightStrip.init(R_DATA, R_CLK); - effect = &bottomUp; + effect = &solidValue; } void Effects::run(Data &data){ @@ -32,8 +32,9 @@ bool Effects::blinkerOrEffect(Strip &strip, Data &data, bool blink){ if(blink){ strobe.run(strip, data); }else{ - strip.setBlack(); - effect->run(strip, data); + strip.setBlack(); + effect->run(strip, data); + bumps.run(strip, data); } strip.update(); } diff --git a/lib/AcceleratedLED328/lib/Effects.h b/lib/AcceleratedLED328/lib/Effects.h index 282cbec..69a34ed 100644 --- a/lib/AcceleratedLED328/lib/Effects.h +++ b/lib/AcceleratedLED328/lib/Effects.h @@ -3,8 +3,10 @@ #include "Effect.h" #include "NoEffect.h" -#include "BottomUp.h" +//#include "BottomUp.h" #include "Strobe.h" +#include "Bumps.h" +#include "SolidValue.h" const uint8_t UPDATE_DURRATION = 15; @@ -22,8 +24,10 @@ class Effects{ Effect* effect; //NoEffect noEffect; - BottomUp bottomUp; + //BottomUp bottomUp; + SolidValue solidValue; Strobe strobe; + Bumps bumps; bool blinkerOrEffect(Strip &strip, Data &data, bool blink); }; diff --git a/lib/AcceleratedLED328/lib/Pixel.cpp b/lib/AcceleratedLED328/lib/Pixel.cpp index f7d966a..5c97b00 100644 --- a/lib/AcceleratedLED328/lib/Pixel.cpp +++ b/lib/AcceleratedLED328/lib/Pixel.cpp @@ -24,6 +24,13 @@ void Pixel::set(uint16_t h, uint8_t s, uint8_t v){ void Pixel::setBlack(){ hsv.val = 0; } +void Pixel::setValue(uint8_t v){ + hsv.val = v; +} + +void Pixel::multiplyValue(uint8_t factor){ + hsv.val = (uint16_t)hsv.val * (uint16_t)factor / (0xFF >> 1); +} uint32_t Pixel::color() { diff --git a/lib/AcceleratedLED328/lib/Pixel.h b/lib/AcceleratedLED328/lib/Pixel.h index 87ee01d..115135c 100644 --- a/lib/AcceleratedLED328/lib/Pixel.h +++ b/lib/AcceleratedLED328/lib/Pixel.h @@ -15,6 +15,8 @@ class Pixel{ void setFrom(Pixel* pixel); void set(uint16_t h, uint8_t s, uint8_t v); void setBlack(); + void setValue(uint8_t v); + void multiplyValue(uint8_t factor); }; diff --git a/lib/AcceleratedLED328/lib/Range.cpp b/lib/AcceleratedLED328/lib/Range.cpp new file mode 100644 index 0000000..c5fc11c --- /dev/null +++ b/lib/AcceleratedLED328/lib/Range.cpp @@ -0,0 +1,29 @@ +#ifndef RANGE_CPP +#define RANGE_CPP + +#include "Range.h" + +template Range::Range(){ + max = T(0); + min = T(0); +} + +template void Range::set(T newMin, T newMax){ + max = newMax; + min = newMin; +} + +template void Range::update(T newValue){ + if(newValue > max){ + max = newValue; + } + if(newValue < min){ + min = newValue; + } +} + +template T Range::average(){ + return max/T(2) + min/T(2); +} + +#endif diff --git a/lib/AcceleratedLED328/lib/Range.h b/lib/AcceleratedLED328/lib/Range.h new file mode 100644 index 0000000..0276742 --- /dev/null +++ b/lib/AcceleratedLED328/lib/Range.h @@ -0,0 +1,15 @@ +#ifndef RANGE_H +#define RANGE_H + +template class Range { + + public: + Range(); + void set(T min, T max); + void update(T newValue); + T average(); + T min; + T max; +}; + +#endif diff --git a/lib/AcceleratedLED328/lib/SolidValue.cpp b/lib/AcceleratedLED328/lib/SolidValue.cpp new file mode 100644 index 0000000..7bfc112 --- /dev/null +++ b/lib/AcceleratedLED328/lib/SolidValue.cpp @@ -0,0 +1,17 @@ +#include "SolidValue.h" + +SolidValue::SolidValue(){ + maxBrake = 0; +} + +void SolidValue::run(Strip &strip, Data &data){ + int16_t currBrake = max(0, -data.acceleration.y); + maxBrake = max(maxBrake, -data.acceleration.y); + + uint8_t brakeValue = map(currBrake, 0, maxBrake, 100, 0xFF); + + strip.setColor(ColorHSV(HUE_RED, 0xFF, brakeValue)); +} + + + diff --git a/lib/AcceleratedLED328/lib/SolidValue.h b/lib/AcceleratedLED328/lib/SolidValue.h new file mode 100644 index 0000000..c2092a7 --- /dev/null +++ b/lib/AcceleratedLED328/lib/SolidValue.h @@ -0,0 +1,15 @@ +#ifndef SOLID_VALUE_H +#define SOLID_VALUE_H + +#include "Effect.h" + +class SolidValue: public Effect { + public: + SolidValue(); + void run(Strip &strip, Data &data); + + private: + int16_t maxBrake; +}; + +#endif