Arduino Forum

Products => The Arduino Starter Kit and Basic Kit => Topic started by: wahu on Nov 01, 2015, 09:10 pm

Title: Can't get accelerometer to work with rgb led
Post by: wahu on Nov 01, 2015, 09:10 pm
We've connected an addressable RGB LED to our Arduino Uno and successfully got it to display whatever colors we needed. It uses the Adafruit Neopixel library located here: https://github.com/adafruit/Adafruit_NeoPixel

Unfortunately, when we added in code to receive the x, y, and z values from the accelerometer, the led stops working. So we're just trying to figure out why the LED stops working after the analogReads. Any help is appreciated.

here is the code:


#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN 8

Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_RGB);

int accel_x, accel_y, accel_z;
int r, g, b;

void setup() {
  Serial.begin(9600);

  strip.begin();
  strip.show();
}

void loop() {
  accel_x = analogRead(0);
  accel_y = analogRead(1);
  accel_z = analogRead(2);

  strip.setPixelColor(0, strip.Color(0, 255 , 0));
  strip.show();
}