Hey Guys, I am using the MPU6050 to switch in between two animations i

Hey Guys,

I am using the MPU6050 to switch in between two animations i have done. I can not make them communicate together but then again I’m a total beginner and I was wondering if any can help?

here is my code

#include “FastLED.h”

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include “I2Cdev.h”
#include “MPU6050.h”

// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include “Wire.h”
#endif

#define SPEED 20

// How many leds in your strip?
#define NUM_LEDS 25

// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 3
#define CLOCK_PIN 13

MPU6050 accelgyro;
//MPU6050 accelgyro(0x69); // ← use for AD0 high

int16_t ax, ay, az;
int16_t gx, gy, gz;

#define OUTPUT_READABLE_ACCELGYRO

// Define the array of leds
CRGB leds[NUM_LEDS];
TBlendType currentBlending;

boolean state = true;

void setup() {
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);

#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif

// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it’s really up to you depending on your project)
Serial.begin(115200);

// initialize device
Serial.println(“Initializing I2C devices…”);
accelgyro.initialize();

// verify connection
Serial.println(“Testing device connections…”);
Serial.println(accelgyro.testConnection() ? “MPU6050 connection successful” : “MPU6050 connection failed”);
}

void loop() {
//MPU6050 Serial read

if (Serial.available() > 0) {
byte inByte;
inByte = Serial.read();
if (inByte == ‘A’) {
state = true;
};
if (inByte == ‘B’) {
state = false;
};
}
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

// these methods (and a few others) are also available
//accelgyro.getAcceleration(&ax, &ay, &az);
//accelgyro.getRotation(&gx, &gy, &gz);

#ifdef OUTPUT_READABLE_ACCELGYRO
// display tab-separated accel/gyro x/y/z values
Serial.print(“a/g:\t”);
Serial.print(ax); Serial.print(“\t”);
Serial.print(ay); Serial.print(“\t”);
Serial.print(az); Serial.print(“\t”);
Serial.print(gx); Serial.print(“\t”);
Serial.print(gy); Serial.print(“\t”);
Serial.println(gz);
#endif

//Stationary Mode
if (state == true) {

 for( int colorStep=0; colorStep<256; colorStep++ ) {

  int r = colorStep;
  int b = 225-colorStep;
  int g = 0;

  for(int x = 0; x < NUM_LEDS; x++){
  leds[x] = CRGB(r,g,b);
  }
  
  FastLED.show();
  FastLED.delay(800 / SPEED);
  delay(10); 

}

for (int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
 
  currentBlending = LINEARBLEND;
  leds[whiteLed] = CRGB::BlueViolet;
  FastLED.show();
  FastLED.delay(1500 / SPEED);
  currentBlending = LINEARBLEND;
   fadeToBlackBy( leds, NUM_LEDS, 30);
}

  for (int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = (whiteLed + 1) ){

  leds[whiteLed] = CRGB::MidnightBlue;
  FastLED.show();
  FastLED.delay(2000 / SPEED);
  fadeToBlackBy( leds, NUM_LEDS, 30);
  currentBlending = LINEARBLEND;
  
  }

}

//motion mode

if (state == false)
{

for (int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
  fadeToBlackBy( leds, NUM_LEDS, 20);
  FastLED.show();
  leds[whiteLed] = CRGB::Grey;
}
   for (int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
  fadeToBlackBy( leds, NUM_LEDS, 100);
  FastLED.show();
  leds[whiteLed] = CRGB::White;
} 

}
}

Have you verified the MPU6050 and the library to control it works with a sketch without any FastLED in it?

See Daniel’s response in the duplicate post.
https://plus.google.com/u/0/107337050102824823455/posts/JydVdkXysq5