#include #include #include #ifdef __AVR__ #include #endif #define PIN 6 #define NUM_PIXELS 138 // Parameter 1 = number of pixels in strip // Parameter 2 = Arduino pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) // NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXELS, PIN, NEO_GRB + NEO_KHZ800); int16_t axRaw, ayRaw, azRaw, gxRaw, gyRaw, gzRaw, temperature; CRGBArray leds; void setup() { // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket #if defined (__AVR_ATtiny85__) if (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif // End of trinket special code FastLED.addLeds(leds, NUM_PIXELS); strip.begin(); strip.setBrightness(200); strip.show(); // Initialize all pixels to 'off' Serial.begin(9600); Wire.begin(); TWBR = 12; Wire.beginTransmission(0x68); Wire.write(0x6B); Wire.write(0x00); Wire.endTransmission(); Wire.beginTransmission(0x68); Wire.write(0x1C); Wire.write(0x10); Wire.endTransmission(); Wire.beginTransmission(0x68); Wire.write(0x1B); Wire.write(0x08); Wire.endTransmission(); Wire.beginTransmission(0x68); Wire.write(0x1A); Wire.write(0x05); Wire.endTransmission(); } void loop() { Wire.beginTransmission(0x68); Wire.write(0x3B); Wire.endTransmission(); Wire.requestFrom(0x68, 14); while (Wire.available() < 14); axRaw = Wire.read() << 8 | Wire.read(); ayRaw = Wire.read() << 8 | Wire.read(); azRaw = Wire.read() << 8 | Wire.read(); temperature = Wire.read() << 8 | Wire.read(); gxRaw = Wire.read() << 8 | Wire.read(); gyRaw = Wire.read() << 8 | Wire.read(); gzRaw = Wire.read() << 8 | Wire.read(); Serial.print(axRaw); Serial.print(","); Serial.print(ayRaw); Serial.print(","); Serial.print(azRaw); Serial.print(","); Serial.print(gxRaw); Serial.print(","); Serial.print(gyRaw); Serial.print(","); Serial.println(gzRaw); if (gzRaw > 15000){ knightRider1(1, 5, 2, 0xFFFFFF); // Cycles, Speed, Width, RGB Color (white) } if (gzRaw < -15000){ knightRider2(1, 5, 2, 0xFFFFFF); // Cycles, Speed, Width, RGB Color (white) } if (gyRaw > 3000 ) { static uint8_t hue; for(int i = 0; i < NUM_PIXELS/2; i++) { // fade everything out leds.fadeToBlackBy(40); // let's set an led value leds[i] = CHSV(hue++,255,255); // now, let's first 20 leds to the top 20 leds, leds(NUM_PIXELS/2,NUM_PIXELS-1) = leds(NUM_PIXELS/2 - 1 ,0); FastLED.delay(33); } FastLED.clear(); } } void knightRider1(uint16_t cycles, uint16_t speed, uint8_t width, uint32_t color) { uint32_t old_val[NUM_PIXELS]; // up to 256 lights! // Larson time baby! // for (int count = 1; count0; x--) { old_val[x-1] = dimColor(old_val[x-1], width); strip.setPixelColor(x-1, old_val[x-1]); } strip.show(); delay(speed); } } void knightRider2(uint16_t cycles, uint16_t speed, uint8_t width, uint32_t color) { uint32_t old_val[NUM_PIXELS]; // up to 256 lights! // Larson time baby! // for (int count = NUM_PIXELS-1; count>=0; count--) { for (int count = NUM_PIXELS-1; count>-8; count--) { strip.setPixelColor(count, color); old_val[count] = color; for(int x = count; x<=NUM_PIXELS ;x++) { old_val[x-1] = dimColor(old_val[x-1], width); strip.setPixelColor(x+1, old_val[x+1]); } strip.show(); delay(speed); } } uint32_t dimColor(uint32_t color, uint8_t width) { return (((color&0xFF0000)/width)&0xFF0000) + (((color&0x00FF00)/width)&0x00FF00) + (((color&0x0000FF)/width)&0x0000FF); } // Fill the dots one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i