Created
May 17, 2014 10:52
-
-
Save elbruno/84935092ba2a7a86d580 to your computer and use it in GitHub Desktop.
ArduinoAccelerometerLightStrip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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