Skip to content

Commit

Permalink
Add Bumps
Browse files Browse the repository at this point in the history
  • Loading branch information
bguest committed Nov 15, 2018
1 parent cddb9c8 commit 4b8877b
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 5 deletions.
38 changes: 38 additions & 0 deletions lib/AcceleratedLED328/lib/Bumps.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,45 @@
#include "Bumps.h"
#include "Range.cpp"

Bumps::Bumps(){
for(uint8_t i=0; i<STRIP_LENGTH; i++){
values[i] = 0;
}
currValue.set(INT16_MAX, INT16_MIN);
maxValue.set(INT16_MAX, INT16_MIN);
}

void Bumps::run(Strip &strip, Data &data){
unsigned long currMillis = millis();
unsigned long STEP_TIME = 40;

currValue.update(data.acceleration.x);
maxValue.update(data.acceleration.x);

if(currMillis - lastStep > 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;
}
7 changes: 7 additions & 0 deletions lib/AcceleratedLED328/lib/Bumps.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@

#include "Arduino.h"
#include "Effect.h"
#include "Range.h"

class Bumps: public Effect {
public:
Bumps();
void run(Strip &strip, Data &data);

private:
Range<int16_t> maxValue;
Range<int16_t> currValue;

unsigned long lastStep;

void pushValue(uint16_t value);
uint16_t values[STRIP_LENGTH];
};

Expand Down
7 changes: 4 additions & 3 deletions lib/AcceleratedLED328/lib/Effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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();
}
8 changes: 6 additions & 2 deletions lib/AcceleratedLED328/lib/Effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
};
Expand Down
7 changes: 7 additions & 0 deletions lib/AcceleratedLED328/lib/Pixel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
2 changes: 2 additions & 0 deletions lib/AcceleratedLED328/lib/Pixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

};

Expand Down
29 changes: 29 additions & 0 deletions lib/AcceleratedLED328/lib/Range.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ifndef RANGE_CPP
#define RANGE_CPP

#include "Range.h"

template <class T> Range<T>::Range(){
max = T(0);
min = T(0);
}

template <class T> void Range<T>::set(T newMin, T newMax){
max = newMax;
min = newMin;
}

template <class T> void Range<T>::update(T newValue){
if(newValue > max){
max = newValue;
}
if(newValue < min){
min = newValue;
}
}

template <class T> T Range<T>::average(){
return max/T(2) + min/T(2);
}

#endif
15 changes: 15 additions & 0 deletions lib/AcceleratedLED328/lib/Range.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef RANGE_H
#define RANGE_H

template <class T> class Range {

public:
Range();
void set(T min, T max);
void update(T newValue);
T average();
T min;
T max;
};

#endif
17 changes: 17 additions & 0 deletions lib/AcceleratedLED328/lib/SolidValue.cpp
Original file line number Diff line number Diff line change
@@ -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));
}



15 changes: 15 additions & 0 deletions lib/AcceleratedLED328/lib/SolidValue.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4b8877b

Please sign in to comment.