The bike glove acts as a turn signal for active bike riders. The glove is connected to the analog that’s lights up if you turn your hand outwards. A right turn will have the glove light up while, a left would not. This is the code.
/////////////////////////////////////////////////////////////////////////////// // Circuit Playground Bike Glove – With “On/Off” // // Author: Carter Nelson // MIT License (https://opensource.org/licenses/MIT) #include <Adafruit_CircuitPlayground.h> #define THRESHOLD_UP 5 // threshold for hand up test #define THRESHOLD_RIGHT 5 // threshold for right turn #define THRESHOLD_LEFT -5 // threshold for left turn #define BRIGHTNESS 255 #define LEFT_COLOR 0xFFFFFF #define RIGHT_COLOR 0xFFFFFF #define ANIM_DELAY 200 /////////////////////////////////////////////////////////////////////////////// void leftTurnAnimation() { // just to be sure, turn off all NeoPixels CircuitPlayground.clearPixels(); // Turn on 5 & 4 CircuitPlayground.setPixelColor(5, LEFT_COLOR); CircuitPlayground.setPixelColor(4, LEFT_COLOR); delay(ANIM_DELAY); CircuitPlayground.clearPixels(); // Turn on 6 & 3 CircuitPlayground.setPixelColor(6, LEFT_COLOR); CircuitPlayground.setPixelColor(3, LEFT_COLOR); delay(ANIM_DELAY); CircuitPlayground.clearPixels(); // Turn on 7 & 2 CircuitPlayground.setPixelColor(7, LEFT_COLOR); CircuitPlayground.setPixelColor(2, LEFT_COLOR); delay(ANIM_DELAY); CircuitPlayground.clearPixels(); // Turn on 8 & 1 CircuitPlayground.setPixelColor(8, LEFT_COLOR); CircuitPlayground.setPixelColor(1, LEFT_COLOR); delay(ANIM_DELAY); CircuitPlayground.clearPixels(); // Turn on 9 & 0 CircuitPlayground.setPixelColor(9, LEFT_COLOR); CircuitPlayground.setPixelColor(0, LEFT_COLOR); delay(ANIM_DELAY); CircuitPlayground.clearPixels(); } /////////////////////////////////////////////////////////////////////////////// void rightTurnAnimation() { // just to be sure, turn off all NeoPixels CircuitPlayground.clearPixels(); // turn on NeoPixels to make an arrow shape CircuitPlayground.setPixelColor(2, RIGHT_COLOR); CircuitPlayground.setPixelColor(5, RIGHT_COLOR); CircuitPlayground.setPixelColor(6, RIGHT_COLOR); CircuitPlayground.setPixelColor(7, RIGHT_COLOR); CircuitPlayground.setPixelColor(8, RIGHT_COLOR); CircuitPlayground.setPixelColor(9, RIGHT_COLOR); // wait a little bit delay(ANIM_DELAY); // turn them all off CircuitPlayground.clearPixels(); // wait again delay(ANIM_DELAY); } /////////////////////////////////////////////////////////////////////////////// void setup() { CircuitPlayground.begin(BRIGHTNESS); } /////////////////////////////////////////////////////////////////////////////// void loop() { // check slide switch position if (CircuitPlayground.slideSwitch()) { // check for hand up or down if (CircuitPlayground.motionZ() > THRESHOLD_UP) { // do nothing } else { // check for right turn if (CircuitPlayground.motionX() > THRESHOLD_RIGHT) { rightTurnAnimation(); // check for left turn } else if (CircuitPlayground.motionY() < THRESHOLD_LEFT) { leftTurnAnimation(); } } } }