Skip to content

Instantly share code, notes, and snippets.

@elbruno
Created May 17, 2014 10:52
Show Gist options
  • Save elbruno/84935092ba2a7a86d580 to your computer and use it in GitHub Desktop.
Save elbruno/84935092ba2a7a86d580 to your computer and use it in GitHub Desktop.
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