Created
April 14, 2015 21:16
-
-
Save sqrtofsaturn/67b507d138852b561ffc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
uint32_t MAX_BEAN_SLEEP = 4294967295; | |
int TIMEOUT = 2000; | |
int lastClick = 0; | |
int maxAccel = 0; | |
void wakeup(){ | |
lastClick = millis(); | |
maxAccel = 0; | |
} | |
void setup() { | |
Serial.begin(57600); | |
pinMode(4,INPUT); | |
Bean.attachChangeInterrupt(4, wakeup); | |
Bean.setAccelerationRange(16); | |
} | |
void loop() { | |
if(millis() - lastClick > TIMEOUT){ | |
Bean.setScratchNumber(1, maxAccel); | |
Bean.sleep(MAX_BEAN_SLEEP); | |
return; | |
} | |
AccelerationReading accel = Bean.getAcceleration(); | |
int16_t localMaxAccel = abs(accel.xAxis); | |
if(abs(accel.yAxis) > localMaxAccel){ | |
localMaxAccel = abs(accel.yAxis); | |
} | |
if(abs(accel.zAxis) > localMaxAccel){ | |
localMaxAccel = abs(accel.zAxis); | |
} | |
if(localMaxAccel > maxAccel){ | |
maxAccel = localMaxAccel; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment