Created
October 10, 2016 15:26
-
-
Save mischa/49c945bb419aba429602b7211ae82a1d to your computer and use it in GitHub Desktop.
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
/* GTD IV: San Diego | |
* | |
* | |
*/ | |
#include <Wire.h> | |
#include <Adafruit_MMA8451.h> | |
#include <Adafruit_Sensor.h> | |
Adafruit_MMA8451 mma = Adafruit_MMA8451(); | |
const int buttonPin = 2; // button pin | |
int buttonState = 0; | |
const int ledLeft = 11; | |
const int ledRight = 10; | |
int incomingByte; | |
unsigned long previousMillis = 0; | |
int gap = 500; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(buttonPin, INPUT); | |
pinMode(ledLeft, OUTPUT); | |
pinMode(ledRight, OUTPUT); | |
if (! mma.begin()) { | |
//Serial.println("Debug: Couldnt start"); | |
while (1); | |
} | |
//Serial.println("Debug: MMA8451 found!"); | |
mma.setRange(MMA8451_RANGE_2_G); | |
} | |
void loop() { | |
int buttonState = digitalRead(buttonPin); | |
mma.read(); | |
sensors_event_t event; | |
mma.getEvent(&event); | |
float accX = event.acceleration.x; | |
Serial.print(accX); | |
Serial.print(","); | |
float accY = event.acceleration.y; | |
Serial.print(accY); | |
Serial.print(","); | |
float accZ = event.acceleration.z; | |
Serial.print(accZ); | |
Serial.print(","); | |
Serial.print(buttonState); | |
Serial.println(); | |
/*if (accX < -2) { | |
float ledB = map(accX, -9.00, -2.00, 255, 64); | |
analogWrite(ledLeft, ledB); | |
analogWrite(ledRight, 255 - ledB); | |
Serial.println(ledB); | |
} else if (accX > 2) { | |
float ledB = map(accX, 2.00, 9.00, 64, 255); | |
analogWrite(ledRight, ledB); | |
analogWrite(ledLeft, 255 - ledB); | |
Serial.println(ledB); | |
} else { | |
analogWrite(ledRight, 64); | |
analogWrite(ledLeft, 64); | |
Serial.println(); | |
} */ | |
if(Serial.available() > 0) { | |
incomingByte = Serial.read(); | |
if (incomingByte == 'Z') { | |
// if (millis() > previousMillis + gap) { | |
// previousMillis = millis(); | |
digitalWrite(ledLeft, HIGH); | |
digitalWrite(ledRight, HIGH); | |
//} | |
} | |
} | |
else { | |
digitalWrite(ledLeft, LOW); | |
digitalWrite(ledRight, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment