Hardware Reference
In-Depth Information
storedVector = sqrt ( storedVector );
Serial . print ( "Len: " ); Serial . println ( storedVector );
// wait a bit
delay ( 100 );
// get new data!
accel . getEvent ( & event );
double newVector = event . acceleration . x * event . acceleration . x ;
newVector += event . acceleration . y * event . acceleration . y ;
newVector += event . acceleration . z * event . acceleration . z ;
newVector = sqrt ( newVector );
Serial . print ( "New Len: " ); Serial . println ( newVector );
// are we moving
if ( abs ( newVector - storedVector ) > MOVE_THRESHOLD ) {
Serial . println ( "Twinkle!" );
flashRandom ( 5 , 1 ); // first number is 'wait' delay,
// shorter num == shorter twinkle
flashRandom ( 5 , 3 ); // second number is how many neopixels
// to simultaneously light up
flashRandom ( 5 , 2 );
}
}
void flashRandom ( int wait , uint8_t howmany ) {
for ( uint16_t i = 0 ; i < howmany ; i ++ ) {
// pick a random favorite color!
int c = random ( FAVCOLORS );
int red = myFavoriteColors [ c ][ 0 ];
int green = myFavoriteColors [ c ][ 1 ];
int blue = myFavoriteColors [ c ][ 2 ];
// get a random pixel from the list
int j = random ( strip . numPixels ());
//Serial.print("Lighting up "); Serial.println(j);
// now we will 'fade' it in in 5 steps
for ( int x = 0 ; x < 5 ; x ++ ) {
int r = red * ( x + 1 ); r /= 5 ;
int g = green * ( x + 1 ); g /= 5 ;
int b = blue * ( x + 1 ); b /= 5 ;
strip . setPixelColor ( j , strip . Color ( r , g , b ));
strip . show ();
Search WWH ::




Custom Search