Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ArduinoAccelerometerLightStrip
#include <Wire.h>
#include "MMA7660.h"
MMA7660 acc;
int brightness = 0; // how bright the LED is
int ledStrip = 6; // the pin that the LED is attached to
int accelerometer = 13; // the pin that the accelerometer sensor is attached
int fadeAmount = 5; // how many points to fade the LED by
void setup()
{
acc.init();
pinMode(accelerometer, OUTPUT);
}
void loop()
{
static long cnt = 0;
static long cntout = 0;
float ax, ay, az;
int8_t x, y, z;
acc.getXYZ(&x, &y, &z);
analogWrite(ledStrip, brightness);
brightness = z;
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount;
}
delay(30);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.