Loading...
  Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Led Motorcycle Lights & Arduino Programming With No Delays on: February 16, 2012, 09:09:22 pm
Sorry, I'm not getting what you mean on the state changes. I do have the brake working fully now and I put seperate blink code for each turn signal and it now works. I was getting tripped up try to use the same code for both.

Yes changing the function names is a great idea and I will do that to make it more clear.
2  Using Arduino / Programming Questions / Re: Led Motorcycle Lights & Arduino Programming With No Delays on: February 15, 2012, 10:29:40 pm
John_S,

That did it for the brake light problem! Thanks, I originally had a couple in the wrong place and it wouldn't work. These brackets are confusing!

Kevin
3  Using Arduino / Programming Questions / Re: Led Motorcycle Lights & Arduino Programming With No Delays on: February 15, 2012, 09:21:09 pm
As mentioned I got the interval figured out. I have have the brake light figured out and working except when the 10 flashes happen the transition between high and low is too fast and the led is very dim. Seems to need a interval in between high and low to let the led come to full brightness.

I still haven't figure out the turn signal code problem.

Code:
  /*

   Buttons Turn on and off LEDs connected to outputs
 
   CIRCUIT:
   * LED attached from output pins to ground with current limiting resistor
   * pushbuttons attached to input pins from ground with each pin having a 10k pull up resistor to positive
 
   */

  // constants won't change. They're used here to
  // set pin numbers:
const int buttonPinLT = 2; // the number of the pushbutton pin
const int buttonPinRT = 3; // the number of the pushbutton pin
const int buttonPinBR = 4; // the number of the pushbutton pin
const int buttonPinHL = 5; // the number of the pushbutton pin

const int ledPinLT = 10;   // the number of the LED pin
const int ledPinRT = 11;   // the number of the LED pin
const int ledPinBR = 12;   // the number of the LED pin
const int ledPinHL = 13;   // the number of the LED pin


  //variables for turn signals  Note: This assumes that only one turn signal can be turned on at a time.
long previousMillis = 0;
int ledState = LOW;               // ledState used to set the LED
const long interval = 100;        // interval for Button delay (milliseconds)

  //variables for brake signal
long previousMillisBR = 0;
int ledStateBR = LOW;             // ledState used to set the LED
const long intervalBR = 100;      // interval at which to blink (milliseconds)
int blinkCount = 0;               // keeps track of the number of times that the brake light has blinked


void setup()
{
  // initialize the LED pins as an output:
  pinMode(ledPinLT, OUTPUT);
  pinMode(ledPinRT, OUTPUT);
  pinMode(ledPinBR, OUTPUT);
  pinMode(ledPinHL, OUTPUT);

  // initialize the pushbutton pins as an input:
  pinMode(buttonPinLT, INPUT);
  pinMode(buttonPinRT, INPUT);
  pinMode(buttonPinBR, INPUT);
  pinMode(buttonPinHL, INPUT);
}


void loop()
{
  //Process the left button
  if (digitalRead(buttonPinLT) == LOW)
    TurnOn(ledPinLT);
  else
    TurnOff(ledPinLT);

  //Process the right button
  if (digitalRead(buttonPinRT) == LOW)
    TurnOn(ledPinRT);
  else
    TurnOff(ledPinRT);

  //Process the break
  if (digitalRead(buttonPinBR) == LOW)
    TurnOnBrake(ledPinBR);
  else
    TurnOffBrake(ledPinBR);
}


void TurnOn(int led)
{
  // check to see if it's time to blink the LED; that is, if the
  // difference between the current time and last time you blinked
  // the LED is bigger than the interval at which you want to
  // blink the LED.

  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval)
{
    // save the last time you blinked the LED
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(led, ledState);
}
}


void TurnOff(int led)
{
  digitalWrite(led, LOW); // set the LED off

  // Reset the variables that control the blinking
  previousMillis = 0;
  ledState = LOW;
}


void TurnOnBrake(int led)
{
  //Since we only want the light to blink 10 times, keep track of the number of blinks
  if (blinkCount < 10)
{
    unsigned long currentMillisBR = millis();

    if(currentMillisBR - previousMillisBR > intervalBR)
{
      // save the last time you blinked the LED
      previousMillisBR = currentMillisBR;

      // if the LED is off turn it on and vice-versa:
      if (ledState == LOW)
        ledState = HIGH;
        blinkCount++;
}
      else
        ledState = LOW;

      // set the LED with the ledState of the variable:
      digitalWrite(led, ledState);
}

      //The last time thru the above loop, the brake will be turned on and will stay on.

}

void TurnOffBrake(int led)
{
      digitalWrite(led, LOW); // set the LED off

      // Reset the variables that control the blinking
        blinkCount = 0;
        previousMillisBR = 0;
        ledStateBR = LOW;
}
4  Using Arduino / Programming Questions / Re: Led Motorcycle Lights & Arduino Programming With No Delays on: February 15, 2012, 07:49:22 pm
Ok got it! I have the delay figured out that PaulS was talking about. Just need tofigure out what elase is going wrong, still at a loss on it.

Thanks,
Kevin
5  Using Arduino / Programming Questions / Re: Led Motorcycle Lights & Arduino Programming With No Delays on: February 14, 2012, 08:22:39 pm
I have been studying the code and I am lost. I see where the interval is set to 1000 but that is one second, not sure where the 10 sec problem is unless your are referring to a calculation and I am totally missing that too. Can you show me the trouble spots with out doing it for me?

Thanks,
Kevin
6  Using Arduino / Programming Questions / Re: Led Motorcycle Lights & Arduino Programming With No Delays on: February 13, 2012, 03:14:51 pm
Yes I am using external pull up resistors. I will look over your suggestion on the code at what I overlooked. It is just a whole new way to code especially with doing the delay before. I will get it though it just takes some time to understanding the programming. The 10 second delay is something I missed and will change that, yes that's not good. My bike is a custom Japanese bike so the switches stay on.

Yes I plan on a few features but for now just want to get the core functions working and then build off of that. The main features I want to do are not illegal, I did my research before starting. Of coarse we talked about pulsing the headlight that is one feature and it can not according to Ohio law dim down to more than 17%. I also want to use the rear turn signals as brake lights(will change color for that) and turn signals in the front for small headlights or running lights(will change to white for that). These are just a small bit of what I want to do. Ohio law also states distance at which these should be visible and I will adhere to those laws also.
7  Using Arduino / Programming Questions / Re: Led Motorcycle Lights & Arduino Programming With No Delays on: February 12, 2012, 07:20:28 pm
I have been working on this new code that uses Blink without delay. For some reason I can't get the led's to blink. When I push the buttons the led's just come on until I let go of the button.

Can someone look over the code and make any suggestions?

Sorry it may not look nice and organized.

Code:
/*

Buttons Turn on and off LEDs connected to outputs

CIRCUIT:
* LED attached from output pins to ground with current limiting resistor
* pushbuttons attached to input pins from ground with each pin having a 10k pull up resistor to positive

*/

// constants won't change. They're used here to
// set pin numbers:

const int buttonPinLT = 2; // the number of the pushbutton pin
const int buttonPinRT = 3; // the number of the pushbutton pin
const int buttonPinBR = 4; // the number of the pushbutton pin
const int buttonPinHL = 5; // the number of the pushbutton pin

const int ledPinLT = 10; // the number of the LED pin
const int ledPinRT = 11; // the number of the LED pin
const int ledPinBR = 12; // the number of the LED pin
const int ledPinHL = 13; // the number of the LED pin


//variables for turn signals  Note: This assumes that only one turn signal can be turned on at a time.
long previousMillis = 0;
int ledState = LOW;             // ledState used to set the LED
const long interval = 10000;     // interval at which to blink (milliseconds)

 
//variables for brake signal
long previousMillisBR = 0;
int ledStateBR = LOW;             // ledState used to set the LED
const long intervalBR = 10000;     // interval at which to blink (milliseconds)
int blinkCount = 0;               // keeps track of the number of times that the brake light has blinked

void setup()

{
// initialize the LED pins as an output:
pinMode(ledPinLT, OUTPUT);
pinMode(ledPinRT, OUTPUT);
pinMode(ledPinBR, OUTPUT);
pinMode(ledPinHL, OUTPUT);

// initialize the pushbutton pins as an input:
pinMode(buttonPinLT, INPUT);
pinMode(buttonPinRT, INPUT);
pinMode(buttonPinBR, INPUT);
pinMode(buttonPinHL, INPUT);

}

void loop()

{
//Process the left button
if (digitalRead(buttonPinLT) == LOW)
TurnOn(ledPinLT);
else
TurnOff(ledPinLT);


//Process the right button
if (digitalRead(buttonPinRT) == LOW)
TurnOn(ledPinRT);
else
TurnOff(ledPinRT);


//Process the break
if (digitalRead(buttonPinBR) == LOW)
TurnOnBrake(ledPinBR);
else
TurnOffBrake(ledPinBR);

}





void TurnOn(int led)

{



  // check to see if it's time to blink the LED; that is, if the

  // difference between the current time and last time you blinked

  // the LED is bigger than the interval at which you want to

  // blink the LED.

   unsigned long currentMillis = millis();

  

   if(currentMillis - previousMillis > interval)

   {

// save the last time you blinked the LED

previousMillis = currentMillis;  



// if the LED is off turn it on and vice-versa:

if (ledState == LOW)

  ledState = HIGH;

else

  ledState = LOW;

 

// set the LED with the ledState of the variable:

digitalWrite(led, ledState);

   }



 }



  

void TurnOff(int led)

{

digitalWrite(led, LOW); // set the LED off

// Reset the variables that control the blinking

previousMillis = 0;
ledState = LOW;

}





void TurnOnBrake(int led)

{

//Since we only want the light to blink 10 times, keep track of the number of blinks

if (blinkCount < 10)

{

unsigned long currentMillisBR = millis();



if(currentMillisBR - previousMillisBR > intervalBR)

{

// save the last time you blinked the LED

previousMillisBR = currentMillisBR;



// if the LED is off turn it on and vice-versa:

if (ledState == LOW)

{

ledState = HIGH;

blinkCount++;

}

else

{

  ledState = LOW;

}

 

// set the LED with the ledState of the variable:

digitalWrite(led, ledState);

}

}

//The last time thru the above loop, the brake will be turned on and will stay on.

}





void TurnOffBrake(int led)

{

digitalWrite(led, LOW); // set the LED off

// Reset the variables that control the blinking

blinkCount = 0;

previousMillisBR = 0;
ledStateBR = LOW;

}


Thanks,
Kevin
8  Using Arduino / Programming Questions / Re: Led Motorcycle Lights & Arduino Programming With No Delays on: February 11, 2012, 09:54:37 pm
First let me say thanks for replying! Second for some reason I don't like your tone with your response. Third I'm not here to get a lesson in laws just programming.

I have seen a lot of smart -ss coments on here and that is no way for long term members to treat newbys.

The lights on your bike are fine for you, I am doing a custom bike and I want a custom system. There is people on here doing things that have already been done but that doesn't keep them from learning and that is what the Arduino is for.

The laws a very defined and lighting systems on vehicles but that doesn't make them right. Out of all of the technological advancements car manufacturers have not improved upon these for safety factors. I am looking beyond what the car manufactures haven't done.

Code:
/*

Buttons Turn on and off LEDs connected to outputs

CIRCUIT:
* LED attached from output pins to ground with current limiting resistor
* pushbuttons attached to input pins from ground with each pin having a 10k pull up resistor to positive

*/

// constants won't change. They're used here to
// set pin numbers:

const int buttonPinLT = 2; // the number of the pushbutton pin
const int buttonPinRT = 3; // the number of the pushbutton pin
const int buttonPinBR = 4; // the number of the pushbutton pin
const int buttonPinHL = 5; // the number of the pushbutton pin

const int ledPinLT = 10; // the number of the LED pin
const int ledPinRT = 11; // the number of the LED pin
const int ledPinBR = 12; // the number of the LED pin
const int ledPinHL = 13; // the number of the LED pin

bool isBrakeOn = false;


void setup()

{
// initialize the LED pins as an output:
pinMode(ledPinLT, OUTPUT);
pinMode(ledPinRT, OUTPUT);
pinMode(ledPinBR, OUTPUT);
pinMode(ledPinHL, OUTPUT);

// initialize the pushbutton pins as an input:
pinMode(buttonPinLT, INPUT);
pinMode(buttonPinRT, INPUT);
pinMode(buttonPinBR, INPUT);
pinMode(buttonPinHL, INPUT);

}

void loop()

{
//Process the left button
if (digitalRead(buttonPinLT) == LOW)
{
TurnOn(ledPinLT);
}


//Process the right button
if (digitalRead(buttonPinRT) == LOW)
{
TurnOn(ledPinRT);
}

//Process the brake
if (digitalRead(buttonPinBR) == LOW)
{
TurnOnBrake(ledPinBR);
}
else
{
TurnOff(ledPinBR);
}


}





void TurnOn(int led)

{

for (int i=0;i<3;i++) // flash 3 times & delay
{
digitalWrite(led, HIGH); // set the LED on
delay(250); // wait for a 1/4 second

digitalWrite(led, LOW); // set the LED off
delay(250); // wait for a 1/4 second
}
delay(500); // wait for a 1/2 second

}





void TurnOnBrake(int led)

{

if (isBrakeOn == false)

{

for (int i=0;i<10;i++) // flash 10 times & delay
{
digitalWrite(led, HIGH); // set the LED on
delay(50); // wait for a 1/4 second

digitalWrite(led, LOW); // set the LED off
delay(50); // wait for a 1/4 second
}
digitalWrite(led, HIGH); // set the LED on

isBrakeOn = true;

}

}





void TurnOff(int led)

{

digitalWrite(led, LOW); // set the LED off

isBrakeOn = false;

}


Besides it's my safety on the bike not anyone else, other than the people around me!

Like the old saying goes, If You Don't Have Anything Nice To Say(post) Then Don't Say(post) Anything.
9  Using Arduino / Programming Questions / Led Motorcycle Lights & Arduino Programming With No Delays on: February 11, 2012, 09:05:55 pm
Hello Gang!

I am working on a Turn Signal, Brake Light and Headlight controller for my motorcycle with the Arduino. The issue I have came up with is that while I push a button for the turn signals I get a delay before the brake light will come on(not a good thing smiley-sad ) What I want to find out is there a way I can program the Arduino to not have these delays?

I will need the Headlight to pulse during the day and this will probably tie up the processor during those cycles. I need to have everything able to react when needed, especially the brake light.

I know the bike already has part of the system I am doing but I want it to be enhanced with the Arduino and added features.

Thanks for any help!
Kevin
10  Using Arduino / Programming Questions / Re: New to Arduino - Wanting to flash a led a few counts pause and few counts again on: January 11, 2012, 07:45:41 pm
Ok here is the code. I may not have properly put the brackets where most do but for my sanity I like them right with the code they represent. This is just for one pushbutton and one led. I am going to try and work on adding another button and led for what I will call the right side in the code. I also want to add headlight pulse and brake light flash and steady. Later after this all works good I want to add some special functions plus some rgb show lights when parked.

Code:
/*
  
  Button Turns on and off a light emitting diode(LED) connected to digital  
   pin 13, when pressing a pushbutton attached to pin 2.
 
 
 CIRCUIT:
 * LED attached from pin 13 to ground(on board led)
 * pushbutton attached to pin 2 from ground
 * 10K resistor attached to pin 2 from positive
 
 */

// constants won't change. They're used here to
// set pin numbers:




const int buttonPinLF = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup()

{ // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPinLF, INPUT); }

  void loop()
  
{
    
    // read the state of the pushbutton value:
    buttonState = digitalRead(buttonPinLF);

    // check if the pushbutton is pressed.
    // if it is, the buttonState is Low:
  
    if (buttonState == LOW)       // turn LED on
    

  
  { for (int i=0;i<3;i++)         // flash 3 times & delay
  
    
  { digitalWrite(ledPin, HIGH);   // set the LED on
    delay(500);                   // wait
    
    digitalWrite(ledPin, LOW);    // set the LED off
    delay(500); }                 // wait
  
 
  
  delay(2000); }
    
  else
  
  { // turn LED off:
    digitalWrite(ledPin, LOW); }
    
}
11  Using Arduino / Programming Questions / Re: New to Arduino - Wanting to flash a led a few counts pause and few counts again on: January 11, 2012, 11:01:30 am
Is there a place to post the code like a repository etc.?
12  Using Arduino / Programming Questions / Re: New to Arduino - Wanting to flash a led a few counts pause and few counts again on: January 10, 2012, 08:08:40 am
Great, Thanks! Looks like some great switch logic here.

Yes if you get pulled over by a Ohio State Trooper it's a ticket no matter what!

I was able to put together some code with your help and lloyddean that works great!
13  Community / Local Groups / Arduino Users Group Interest in Columbus Ohio on: January 09, 2012, 03:45:43 pm
Hello All!

Looking to see if there would be any interest for a group to get together like a Users Group for the Arduino in the Columbus Ohio area?

Thanks,
Kevin
14  Using Arduino / Programming Questions / Re: New to Arduino - Wanting to flash a led a few counts pause and few counts again on: January 09, 2012, 03:18:12 pm
Ok how about this question to go with yours, why would anyone create subsets if the original is good enough. So there has to be a difference or else it wouldn't be there!

I have found Arduino is C/C++ AVR GCC

I guess I should have taken the post of topic!
15  Using Arduino / Programming Questions / Re: New to Arduino - Wanting to flash a led a few counts pause and few counts again on: January 09, 2012, 12:06:56 pm
From my understanding from a Nuts & Volt magazine article C is much more versatile and not as limited as C++ for the Arduino.

There are no silly questions, your just silly if you don't ask!  smiley
Pages: [1] 2