LED Brake and TurnSignals/Indicators


hi guys,

thanks far! i'm creating custom rear lights using several strips of leds.

since you've helped me of basic functions of indicator (which struggled until guys helped!), think might time move on combining learning practical functionality of project.

all strips performing same job i've been testing 1 strip.

i've got 2 buttons, 1 brake , 1 indicator. there 3 functions (or function a, function b , function a2), 1 brake light, 1 indicator , 1 both combined.

here's vid of indicator pass:

loop each led

and here's code:

code: [select]
#include "fastled.h"


#define num_leds 15

crgb leds[num_leds];

const int indicatorpin = 2;   
int indicatorstate = 0;         
int currentindicatorled = 0;

void setup() {

 
  pinmode(indicatorpin, input);
  fastled.addleds<ws2812b, 6, rgb>(leds, num_leds);
  fastled.addleds<ws2812b, 5, rgb>(leds, num_leds);
 
}

 void indicatorsweep()
 
{
  if (currentindicatorled < num_leds)
  {
   
    leds[currentindicatorled] = crgb(255, 0, 0);
    fastled.show();
   
    currentindicatorled++;
  }
  else
  {
   
    fastled.clear();
    fastled.show();                           
    delay(100);       

    currentindicatorled = 0;
  }

  delay(35);
 
}


void loop() {

  indicatorstate = digitalread(indicatorpin);

  if (indicatorstate == high) {

    indicatorsweep();
   
  } else {
   
    fastled.clear();
    fastled.show();

    currentindicatorled = 0;
  }
}



my 'void indicatorsweep();' function creating entire sweep 1 button press , button state read after each sweep. now, button state can read each led turns on/off. i've done because think allow me 'read' state of function , turn on 'opposite' leds red when brake light pressed?

i did have 2 buttons in code before, when had 3 separate functions brake, indicator , brake+indicator think objective @ moment work out how turn opposite leds red.

to clarify, when brakes , indicators on, i'd indicators 'sweep' on top of brakes.

will along lines of 'reading' position of current led , turning leds after current led red?

so 'if' brakes && indicators on, read current position of indicator , turn leds after red?

i've tried few things i'm bit stuck.

any appreciated,

thanks again,

kyle

hi guys,

i'm getting somewhere i'm stuck again of specifics of functionality of leds. here's i've got far:

https://www.youtube.com/watch?v=1vr-nunn8g8

i made turn signal green it's clearer in vid , issue have @ moment when let go of turn signal button, leds reset position 0 code dictates. i'd introduce variable causes led 'sweep' continue end of strip if let go of button.

i had before unable check button state of turn signal @ each led in order add brake light @ time in vid.

i've tried adding while loop in several places no luck since i'm unable activcate brake when it's running.

here's code:

code: [select]
#include "fastled.h"


#define num_leds 16

crgb leds[num_leds];

const int indicatorpin = 2;   
int indicatorstate = 0;         
const int brakepin = 1;
int brakestate = 0;

int currentindicatorled = 0;

void setup() {

 
  pinmode(indicatorpin, input);
  pinmode(brakepin, input);
  fastled.addleds<ws2812b, 6, rgb>(leds, num_leds);
  fastled.addleds<ws2812b, 5, rgb>(leds, num_leds);
  leds.setbrightness(50);
}

 void indicatorsweep()
 
{
  if (currentindicatorled < num_leds)
  {
   
    leds[currentindicatorled] = crgb(255, 0, 0);
       
    currentindicatorled++;

 // deal other leds after current lit indicator led
    (int led = currentindicatorled; led < num_leds; led++)
    {
      // brakes on ?
      if (brakestate == high)
      {
         // light led brake
         leds[led] = crgb(0, 255, 0);       
      }
     
      else
     
      {
         // blank led there no brake
         leds[led] = crgb(0, 0, 0);
    }

   
    fastled.show();
       
    }
  }
 
  else
 
  {

   
    currentindicatorled = 0;

  }

  delay(40);
 
}


void loop() {

  indicatorstate = digitalread(indicatorpin);
  brakestate = digitalread(brakepin);
 
  if (indicatorstate == high) {

    indicatorsweep();
   
  } else {
   
    fastled.clear();
    fastled.show();

    currentindicatorled = 0;
  }
}






i hope makes sense. can think of suggestion?

as always, again far.

kyle


Arduino Forum > Using Arduino > Programming Questions > LED Brake and TurnSignals/Indicators


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'