LED Strip + Accelerometer, Stopping & Starting Loop

Hi Forum just following up here.

I couldn't find a way for the accelerometer to just detect any motion, so I decided to use x,y,z coordinates instead. Which was a bit of a pain but hey good practice.

So when the book housing the UNO/accelerometer is stationary the LED strip is green. When tilted to about a 20 degree angle it turns purple, and then at about 60 degrees it'll go rainbow.

The only issue so far is that my three RGB LED strips connected together (432 LEDs total) can't show the color white. Which makes my rainbow setting janky as shit. Doing some digging on this site think that might be a power issue. Right now I have a 9v charger going into 12v-->5v converter. I have a 12v adapter on the way and hopefully that'll remedy it. If not, whatever.

Long story longer here's the code I'm rolling with now.

<
#include <Adafruit_NeoPixel.h>
#include <Wire.h>

#define PIN 6                                             
#define COLOR_ORDER GRB                                      
#define LED_TYPE WS2812B                                      
#define NUMPIXELS 400   




Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
int delayval = 2000;
int stillTime = 2000;
bool blinkState = 0;
bool running = false;
bool myOutput = false;
unsigned long loopTime = 0;          
unsigned long interruptsTime = 0;   
const int MPU_ADDR = 0x68; 
int16_t accelerometer_x, accelerometer_y, accelerometer_z; 
int16_t gyro_x, gyro_y, gyro_z; // variables for gyro raw data
int16_t temperature; 
char tmp_str[7]; 
char* convert_int16_to_str(int16_t i) {
 sprintf(tmp_str, "%6d", i);
 return tmp_str;
}


void setup() {
 pixels.begin();

 Serial.begin(9600);
 pinMode(PIN, OUTPUT);
 digitalWrite(PIN, HIGH);
 digitalWrite(PIN, LOW);
 delay(1000);
 Wire.begin();
 Wire.beginTransmission(MPU_ADDR); 
 Wire.write(0x6B); 
 Wire.write(0); 
 Wire.endTransmission(true);

} 

 

void loop() {


   if (accelerometer_x > 15000 && accelerometer_y < -200 && accelerometer_y > -2200) {
   for (int i = 0; i < NUMPIXELS; i++) {
     pixels.setPixelColor(i, pixels.Color(0, 5, 200));
     pixels.show();
   }
   delay(2000);
 }
     if (accelerometer_x > 15000 && accelerometer_y < -3200 && accelerometer_y > -5000) {
   for (int i = 0; i < NUMPIXELS; i++) {
     pixels.setPixelColor(i, pixels.Color(150, 8, 0));
     pixels.show();
   }
   delay(2000);
 }
     if (accelerometer_x > 15000 && accelerometer_y < -5600 && accelerometer_y > -8000) {
   for (int i = 0; i < NUMPIXELS; i++) {
     (rainbow(1));
     pixels.show();
   }
   delay(2000);
     }  
 
 Wire.beginTransmission(MPU_ADDR);
 Wire.write(0x3B); 
 Wire.endTransmission(false); 
 Wire.requestFrom(MPU_ADDR, 7 * 2, true); 

 // "Wire.read()<<8 | Wire.read();" means two registers are read and stored in the same variable
 accelerometer_x = Wire.read() << 8 | Wire.read(); 
 accelerometer_y = Wire.read() << 8 | Wire.read(); 
 accelerometer_z = Wire.read() << 8 | Wire.read();
 temperature = Wire.read() << 8 | Wire.read(); 
 gyro_x = Wire.read() << 8 | Wire.read(); 
 gyro_y = Wire.read() << 8 | Wire.read(); 
 gyro_z = Wire.read() << 8 | Wire.read(); 

 Serial.print("aX = "); Serial.print(convert_int16_to_str(accelerometer_x));
 Serial.print(" | aY = "); Serial.print(convert_int16_to_str(accelerometer_y));
 Serial.print(" | aZ = "); Serial.print(convert_int16_to_str(accelerometer_z));
 Serial.print(" | tmp = "); Serial.print(temperature / 340.00 + 36.53);
 Serial.print(" | gX = "); Serial.print(convert_int16_to_str(gyro_x));
 Serial.print(" | gY = "); Serial.print(convert_int16_to_str(gyro_y));
 Serial.print(" | gZ = "); Serial.print(convert_int16_to_str(gyro_z));
 Serial.println();

}



void rainbow(uint8_t wait) {
 uint16_t i, j;

 for(j=0; j<256; j++) {
   for(i=0; i<pixels.numPixels(); i++) {
     pixels.setPixelColor(i, Wheel((i*1+j) & 255));
   }
   pixels.show();
   delay(2000);
 }
}


// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
 if(WheelPos < 85) {
   return pixels.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
 } 
 else if(WheelPos < 170) {
   WheelPos -= 85;
   return pixels.Color(255 - WheelPos * 3, 0, WheelPos * 3);
 } 
 else {
   WheelPos -= 170;
   return pixels.Color(0, WheelPos * 3, 255 - WheelPos * 3);
 }
}

>

Cheers,
Matt