Motorbike speed based Neopixels.

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
gottobebob
 
Posts: 2
Joined: Tue Nov 11, 2014 12:11 pm

Motorbike speed based Neopixels.

Post by gottobebob »

Hi All
My first project is to use the flora gps to get my speed and use that value to change neopixels on my bike. The idea is that when stopped the lights 'breathe' red and slowly change colour (red, orange, yellow, white) as my speed increases (and decreases). I'm not very experienced but have been able to successfully run basic gps and neopixels programs. I've read some of the aguments over using a different means of aquiring speed but still want to have a go using the gps. I understand I can get the speed using (gps.speed) but I'm strugging on how to get this value to gradually change the colours up and down the scale. If anyone can share some code or point me in the right direction of similar projects would appriciate it.

User avatar
Franklin97355
 
Posts: 23939
Joined: Mon Apr 21, 2008 2:33 pm

Re: Motorbike speed based Neopixels.

Post by Franklin97355 »

I would start by writing the code for the color change and 'breathing' so you have that ready then you can use the speed to do an if/then or switch/case where if speed between 2 and 10 color = red and so on.

User avatar
gottobebob
 
Posts: 2
Joined: Tue Nov 11, 2014 12:11 pm

Re: Motorbike speed based Neopixels.

Post by gottobebob »

Ok so heres a first basic go at the code, basically if there is no fix, one colour else another. Any improvements on the code welcome

Code: Select all

    #include "Adafruit_NeoPixel.h"
    #include "SPI.h"
    #include <Adafruit_GPS.h>
    #include <SoftwareSerial.h>
    Adafruit_GPS GPS(&Serial1);
    //Demonstrates "breathing" effect on

    #define LED_PIN  6   
    #define N_LEDS  30
    Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
    
    int colVAL = 0;

    uint8_t LED_Breathe_Table[]  = {   80,  87,  95, 103, 112, 121, 131, 141, 151, 161, 172, 182, 192, 202, 211, 220,
                  228, 236, 242, 247, 251, 254, 255, 255, 254, 251, 247, 242, 236, 228, 220, 211,
                  202, 192, 182, 172, 161, 151, 141, 131, 121, 112, 103,  95,  87,  80,  73,  66,
                   60,  55,  50,  45,  41,  38,  34,  31,  28,  26,  24,  22,  20,  20,  20,  20,
                   20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,
                   20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  20,  22,  24,  26,  28,
                   31,  34,  38,  41,  45,  50,  55,  60,  66,  73 };


    #define BREATHE_TABLE_SIZE (sizeof(LED_Breathe_Table))
    #define BREATHE_CYCLE    2000      /*breathe cycle in milliseconds*/
    #define BREATHE_UPDATE    (BREATHE_CYCLE / BREATHE_TABLE_SIZE)


    void setup() {
      // Start up the LED strip
      strip.begin();

      // Update the strip, to start they are all 'off'
      strip.show();
    }


    void loop() {
      int cycle;
      int colval = 100*(GPS.speed);
      if (GPS.fix) {
        Serial.print("Fix found: "); Serial.print((int)GPS.fix);
        for (cycle=0; cycle < 4; cycle++) {
            uniformBreathe(LED_Breathe_Table, BREATHE_TABLE_SIZE, BREATHE_UPDATE, 200, 0, colval);
        }
      }
         else {
          Serial.print("No Fix ");
         for (cycle=0; cycle < 4; cycle++) {
            uniformBreathe(LED_Breathe_Table, BREATHE_TABLE_SIZE, BREATHE_UPDATE, 0, 0, 200);
         }
         }
      }

    void uniformBreathe(uint8_t* breatheTable, uint8_t breatheTableSize, uint16_t updatePeriod, uint16_t r, uint16_t g, uint16_t b)
    {
      int i;
      uint8_t breatheIndex = 0;
      uint8_t breatheRed;
      uint8_t breatheGrn;
      uint8_t breatheBlu;
     
      for (breatheIndex = 0; breatheIndex < breatheTableSize; breatheIndex++) {
        for (i=0; i < strip.numPixels(); i++) {
          breatheRed = (r * breatheTable[breatheIndex]) / 256;
          breatheGrn = (g * breatheTable[breatheIndex]) / 256;
          breatheBlu = (b * breatheTable[breatheIndex]) / 256;
          strip.setPixelColor(i, breatheRed, breatheGrn, breatheBlu);
        }
        strip.show();   // write all the pixels out
        delay(updatePeriod);
      }
    }
   
Last edited by Franklin97355 on Wed Nov 12, 2014 2:25 pm, edited 1 time in total.
Reason: Replaced quote tags with code tags

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”