Last active
November 25, 2020 14:12
-
-
Save aristath/722c9afc99cc9f6c134f2c96ce6f0e05 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
#include "CurieIMU.h" | |
#include <Adafruit_DotStar.h> | |
#include <SPI.h> | |
#define NUMPIXELS 60 // Number of LEDs in strip | |
#define MINBRIGHTNESS 100 | |
#define MAXBRIGHTNESS 255 | |
#define DATAPIN 5 | |
#define CLOCKPIN 4 | |
int head = 0, tail = -10; // Index of first 'on' and 'off' pixels | |
Adafruit_DotStar strip(NUMPIXELS, DATAPIN, CLOCKPIN, DOTSTAR_BRG); | |
boolean blinkState = false; // state of the LED | |
unsigned long loopTime = 0; // get the time since program started | |
unsigned long interruptsTime = 0; // get the time when motion event is detected | |
int brightness = 0; | |
boolean goUp = true; | |
void setup() { | |
CurieIMU.begin(); | |
CurieIMU.attachInterrupt(eventCallback); | |
/* Enable Motion Detection */ | |
CurieIMU.setDetectionThreshold(CURIE_IMU_MOTION, 500); // 20mg | |
CurieIMU.setDetectionDuration(CURIE_IMU_MOTION, 250); // trigger times of consecutive slope data points | |
CurieIMU.interrupts(CURIE_IMU_MOTION); | |
strip.begin(); // Initialize pins for output | |
strip.show(); // Turn all LEDs off ASAP | |
} | |
void loop() { | |
stripBreathe(); | |
} | |
/** | |
* Breathe. | |
* | |
* Runs when not on brake mode. | |
*/ | |
void stripBreathe() { | |
if (goUp) { | |
brightness++; | |
if ( MAXBRIGHTNESS <= brightness ) goUp = false; | |
} else { | |
brightness--; | |
if ( MINBRIGHTNESS >= brightness ) goUp = true; | |
} | |
// strip.fill(0xFFFFFF, 0, NUMPIXELS); | |
stripRoll(); | |
strip.setBrightness(brightness); | |
strip.show(); | |
delay(10); | |
} | |
void stripRoll() { | |
strip.setPixelColor(head, 0xFFFFFF); // 'On' pixel at head | |
strip.setPixelColor(tail, 0); // 'Off' pixel at tail | |
if(++head >= NUMPIXELS) { // Increment head index. Off end of strip? | |
head = 0; // Yes, reset head index to start | |
} | |
if(++tail >= NUMPIXELS) tail = 0; // Increment, reset tail index | |
} | |
/** | |
* Blink once. | |
*/ | |
void stripBlink() { | |
strip.fill(0x00FF00, 0, NUMPIXELS); | |
strip.setBrightness(200); strip.show(); | |
delay(17); | |
strip.clear(); | |
strip.show(); | |
delay(40); | |
} | |
/** | |
* Break lights. | |
*/ | |
static void eventCallback(void) { | |
if (CurieIMU.getInterruptStatus(CURIE_IMU_MOTION)) { | |
stripBlink(); | |
stripBlink(); | |
stripBlink(); | |
stripBlink(); | |
stripBlink(); | |
stripBlink(); | |
stripBlink(); | |
stripBlink(); | |
stripBlink(); | |
stripBlink(); | |
interruptsTime = millis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment