Pascal Cotret
Published © GPL3+

Safety jacket for cyclists

Of course, we could wear headlamps, but is there is a way to combine safety and style when we want to turn?

IntermediateShowcase (no instructions)3 hours858
Safety jacket for cyclists

Things used in this project

Hardware components

Flora
Adafruit Flora
×1
Flora BLE Module
Adafruit Flora BLE Module
×1
NeoPixel Ring: WS2812 5050 RGB LED
Adafruit NeoPixel Ring: WS2812 5050 RGB LED
×1
Adafruit Feather 32u4 Bluefruit LE
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic of the safety jacket

Code

Code

Arduino
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN            6
//#define a              0 // a=0 cligno DROIT a=1 cligno GAUCHE
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      24

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 0; // delay for half a second


// this constant won't change:
const int  buttonPinG = 9;    // the pin that the pushbutton is attached to
const int  buttonPinD = 10;    // the pin that the pushbutton is attached to
//const int ledPin = 13;       // the pin that the LED is attached to

// Variables will change:
int buttonState1 = 0;         // current state of the button
int lastButtonState1 = 0;     // previous state of the button
int buttonState2 = 0;         // current state of the button
int lastButtonState2 = 0;     // previous state of the button
int buttonBlink1=0;           // to blink or not to blink, that is the question
int buttonBlink2=0;           // to blink or not to blink, that is the question
int a=0;
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=12*a; i<12*(a+1); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code

  strip.begin(); // This initializes the NeoPixel library
  // initialize the button pin as a input:
  pinMode(buttonPinG, INPUT);
  pinMode(buttonPinD, INPUT);
  // initialize the LED as an output:
  //pinMode(ledPin, OUTPUT);
}

void loop()
{
  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
  buttonState1=digitalRead(buttonPinG);
  buttonState2=digitalRead(buttonPinD);

// compare the buttonState to its previous state
  if (buttonState1 != lastButtonState1)
  {
    // if the state has changed, increment the counter
    if (buttonState1 == HIGH)
    {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonBlink1++;
      a=1;
    }
      delay(50);
      lastButtonState1 = buttonState1;
      
      if (buttonBlink1%2 == 1) {
      // if the current state is LOW then the button
      // wend from on to off:
          // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
          colorWipe(strip.Color(255, 69, 0), 0);
          delay(500);
          colorWipe(strip.Color(0, 0, 0), 0);
          delay(500);
          colorWipe(strip.Color(255, 69, 0), 0);
          delay(500);
          colorWipe(strip.Color(0, 0, 0), 0);
          delay(500);
          colorWipe(strip.Color(255, 69, 0), 0);
          delay(500);
          colorWipe(strip.Color(0, 0, 0), 0);
          delay(500);
          colorWipe(strip.Color(255, 69, 0), 0);
          delay(500);
          colorWipe(strip.Color(0, 0, 0), 0);
          delay(500);
          delay(delayval); // Delay for a period of time (in milliseconds).
      }
      else {
          colorWipe(strip.Color(0, 0, 0), 0);
          delay(1000);
          delay(delayval); // Delay for a period of time (in milliseconds).
      }
       
  }

// compare the buttonState to its previous state
  if (buttonState2 != lastButtonState2)
  {
    // if the state has changed, increment the counter
    if (buttonState2 == HIGH)
    {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonBlink2++;
    }
      delay(50);
      lastButtonState2 = buttonState2;
      
      if (buttonBlink2%2 == 1) {
      // if the current state is LOW then the button
      // wend from on to off:
      a=0;
          // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
          colorWipe(strip.Color(255, 69, 0), 0);
          delay(500);
          colorWipe(strip.Color(0, 0, 0), 0);
          delay(500);
          colorWipe(strip.Color(255, 69, 0), 0);
          delay(500);
          colorWipe(strip.Color(0, 0, 0), 0);
          delay(500);
          colorWipe(strip.Color(255, 69, 0), 0);
          delay(500);
          colorWipe(strip.Color(0, 0, 0), 0);
          delay(500);colorWipe(strip.Color(255, 69, 0), 0);
          delay(500);
          colorWipe(strip.Color(0, 0, 0), 0);
          delay(500);
          delay(delayval); // Delay for a period of time (in milliseconds).
       }
       else {
        colorWipe(strip.Color(0, 0, 0), 0);
        delay(1000);
        delay(delayval); // Delay for a period of time (in milliseconds).
        
       }
}
}

Credits

Youssef Rabah & Grégoire du Fau de Lamothe

Posted by Pascal Cotret
Thanks to Youssef Rabah and Grégoire du Fau de Lamothe.

Comments