-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
140 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |