add startup colors, to keep powerbanks happy

This commit is contained in:
Sophie Schiller 2021-02-18 17:45:44 +01:00
parent 0a89fa271d
commit 1a56e9a6c2

View file

@ -20,9 +20,9 @@ const byte NUM_LEDS = 15;
const byte FRAMES_PER_SECOND = 60; const byte FRAMES_PER_SECOND = 60;
const float range = 0.5; //accelleration range in g const float range = 0.5; //accelleration range in g
byte BRIGHTNESS = 2; byte BRIGHTNESS = 4;
const byte COOLING = 47; const byte COOLING = 80;
const byte SPARKING = 50; const byte SPARKING = 60;
uint8_t gHue = 0; uint8_t gHue = 0;
@ -34,7 +34,7 @@ float h[NUM_BALLS] ; // An array of heights
float vImpact0 = sqrt( -2 * GRAVITY * h0 ); // Impact velocity of the ball when it hits the ground if "dropped" from the top of the strip float vImpact0 = sqrt( -2 * GRAVITY * h0 ); // Impact velocity of the ball when it hits the ground if "dropped" from the top of the strip
float vImpact[NUM_BALLS] ; // As time goes on the impact velocity will change, so make an array to store those values float vImpact[NUM_BALLS] ; // As time goes on the impact velocity will change, so make an array to store those values
float tCycle[NUM_BALLS] ; // The time since the last time the ball struck the ground float tCycle[NUM_BALLS] ; // The time since the last time the ball struck the ground
byte pos[NUM_BALLS] ; // The integer position of the dot on the strip (LED index) byte pos[NUM_BALLS] ; // The integer position of the dot on the strip (LED index)
long tLast[NUM_BALLS] ; // The clock time of the last ground strike long tLast[NUM_BALLS] ; // The clock time of the last ground strike
float COR[NUM_BALLS] ; // Coefficient of Restitution (bounce damping) float COR[NUM_BALLS] ; // Coefficient of Restitution (bounce damping)
@ -47,7 +47,7 @@ CRGB ledsR[NUM_LEDS * STRIPS];
CRGBPalette16 gPal; CRGBPalette16 gPal;
CRGB flagcolors[3][6] {{CRGB::Red, CRGB::DarkOrange, CRGB::Yellow, CRGB::DarkGreen, CRGB::Blue, CRGB::DarkViolet}, CRGB flagcolors[3][6] {{CRGB::Red, CRGB::DarkOrange, CRGB::Yellow, CRGB::DarkGreen, CRGB::Blue, CRGB::DarkViolet},
{CRGB::DarkBlue, CRGB::DeepPink, CRGB::Gray, CRGB::Gray, CRGB::DeepPink, CRGB::DarkBlue}, {CRGB::DarkBlue, CRGB::DeepPink, CRGB::Gray, CRGB::Gray, CRGB::DeepPink, CRGB::DarkBlue},
{CRGB::DeepPink, CRGB::Gray, CRGB::DarkViolet, CRGB::Black, CRGB::Blue, CRGB::Black}}; {CRGB::Green, CRGB::Green, CRGB::Gray, CRGB::Gray, CRGB::Red, CRGB::Red}};
const byte modeSwitchPin = 2; const byte modeSwitchPin = 2;
RotaryEncoder encoder(A2, A3); RotaryEncoder encoder(A2, A3);
@ -62,12 +62,17 @@ void setup() {
FastLED.addLeds<WS2812, 10, GRB>(ledsR, NUM_LEDS * 4, NUM_LEDS).setCorrection( TypicalLEDStrip ); FastLED.addLeds<WS2812, 10, GRB>(ledsR, NUM_LEDS * 4, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.addLeds<WS2812, 11, GRB>(ledsR, NUM_LEDS * 5, NUM_LEDS).setCorrection( TypicalLEDStrip ); FastLED.addLeds<WS2812, 11, GRB>(ledsR, NUM_LEDS * 5, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS ); FastLED.setBrightness( BRIGHTNESS );
FastLED.setMaxPowerInVoltsAndMilliamps(5,500);
fill_rainbow(ledsR, NUM_LEDS*STRIPS, 0, 5);
FastLED.show();
pinMode(modeSwitchPin, INPUT_PULLUP); pinMode(modeSwitchPin, INPUT_PULLUP);
pinMode(3, OUTPUT); pinMode(3, OUTPUT);
pinMode(4, OUTPUT); pinMode(4, OUTPUT);
pinMode(5, OUTPUT); pinMode(5, OUTPUT);
digitalWrite(3, HIGH);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
attachInterrupt(digitalPinToInterrupt(modeSwitchPin), setMode, RISING); attachInterrupt(digitalPinToInterrupt(modeSwitchPin), setMode, RISING);
PCICR |= (1 << PCIE1); PCICR |= (1 << PCIE1);
@ -302,6 +307,11 @@ void drawOff(){
fadeToBlackBy( leds, STRIPS*NUM_LEDS, 10); fadeToBlackBy( leds, STRIPS*NUM_LEDS, 10);
} }
void rainbow()
{
fill_rainbow( leds, NUM_LEDS * STRIPS, gHue, 5);
}
void setMode(){ void setMode(){
static unsigned long last_interrupt_time = 0; static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis(); unsigned long interrupt_time = millis();
@ -370,8 +380,9 @@ void loop() {
if (mode == 0) { if (mode == 0) {
// === Read acceleromter data === // // === Read acceleromter data === //
float accCombined = calculateOrientationData(); //float accCombined = calculateOrientationData();
enableLEDsOnAcceleration(accCombined); //enableLEDsOnAcceleration(accCombined);
rainbow();
} }
else if ((mode == 1) || (mode == 2)) { else if ((mode == 1) || (mode == 2)) {
random16_add_entropy( random()); random16_add_entropy( random());
@ -392,7 +403,7 @@ void loop() {
else { else {
drawOff(); drawOff();
} }
FastLED.setBrightness( BRIGHTNESS * 8 ); FastLED.setBrightness( BRIGHTNESS * 4 );
if (mode != 2){ if (mode != 2){
for (uint8_t i=0; i<NUM_LEDS*STRIPS; i++) { for (uint8_t i=0; i<NUM_LEDS*STRIPS; i++) {
ledsR[NUM_LEDS*STRIPS-1-i] = leds[i]; ledsR[NUM_LEDS*STRIPS-1-i] = leds[i];
@ -408,5 +419,3 @@ void loop() {
gHue++; gHue++;
FastLED.delay(1000 / FRAMES_PER_SECOND); FastLED.delay(1000 / FRAMES_PER_SECOND);
} }