11
11
12
12
#define dataPin 2 // Yellow wire on Adafruit Pixels
13
13
#define clockPin 3 // Green wire on Adafruit Pixels
14
- #define stripLen 200
14
+ #define stripLen 40
15
15
16
16
volatile unsigned long int interrupt_counter; // how many ms have elapsed since the interrupt timer was last reset
17
17
unsigned long int prev_interrupt_counter; // the main loop uses this to detect when the interrupt counter has changed
@@ -41,13 +41,12 @@ void setup()
41
41
strip.begin ();
42
42
strip.setAll (rgbInfo_t (0 ,0 ,0 ));
43
43
44
- library_update = &Zoa_WS2801::pushFront;
45
-
46
- switch_after = 3000 ;
44
+ switch_after = 5000 ;
47
45
interrupt_counter = switch_after + 1 ;
48
46
prev_interrupt_counter = interrupt_counter;
49
47
active_routine = 0 ;
50
48
update = NULL ;
49
+ library_update = NULL ;
51
50
52
51
// update the interrupt counter (and thus the LEDs) every 30ms. The strip updating takes ~0.1ms
53
52
// for each LED in the strip, and we are assuming a maximum strip length of 240, plus some extra wiggle room.
@@ -89,15 +88,15 @@ void loop()
89
88
case 0 :
90
89
// green and blue waves going in and out of phase
91
90
update = update_simple;
92
- waves[0 ] = new Sine_generator ( 0 , 15 , 1 , 0 );
91
+ waves[0 ] = new Sine_generator ( 0 , 15 , 1 , PI/ 2 );
93
92
// all the /3s are a quick way to get the speed looking right while maintaining prime number ratios
94
93
waves[1 ] = new Sine_generator ( 20 , 255 , 11 /3 , 0 );
95
94
waves[2 ] = new Sine_generator ( 20 , 255 , 17 /3 , 0 );
96
95
break ;
97
96
case 1 :
98
97
// green and purple waves, same frequency but out of phase
99
98
update = update_simple;
100
- waves[0 ] = new Sine_generator ( 0 , 5 , 5 /3 , PI/ 2 );
99
+ waves[0 ] = new Sine_generator ( 0 , 5 , 5 /3 , 0 );
101
100
waves[1 ] = new Sine_generator ( 0 , 200 , 5 /3 , 0 );
102
101
waves[2 ] = new Sine_generator ( 0 , 255 , 5 /3 , PI/2 );
103
102
break ;
@@ -196,7 +195,7 @@ void linear_transition()
196
195
void linear_transition ( const rgbInfo& start_value, const rgbInfo& target_value, uint16_t ms )
197
196
{
198
197
float stop_cnt = interrupt_counter + ms;
199
- while ( interrupt_counter <= stop_cnt )
198
+ while ( interrupt_counter < stop_cnt )
200
199
{
201
200
while ( interrupt_counter == prev_interrupt_counter ) {}
202
201
prev_interrupt_counter = interrupt_counter;
@@ -222,8 +221,16 @@ void update_interrupt_counter()
222
221
}
223
222
224
223
// Used for transitions between routines (hypothetically)
225
- float transitional_value ( const float & from, const float & to, const float & multiplier )
224
+ float transitional_value ( const float & from, const float & to, float multiplier )
226
225
{
226
+ if ( multiplier < 0 )
227
+ {
228
+ multiplier = 0 ;
229
+ }
230
+ else if ( multiplier > 1 )
231
+ {
232
+ multiplier = 1 ;
233
+ }
227
234
float val = from * (1 -multiplier) + to * multiplier;
228
235
return val;
229
236
}
0 commit comments