Go Down

Topic: Can't get accelerometer to work with rgb led (Read 833 times) previous topic - next topic

wahu

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();
}

Go Up