if condition and Analog pin to eliminate boot load time

Hello

I am running a code to light up addressable LEDs using an Arduino nano.
it takes about 6 Seconds for the Ardunio to boot up when the power is connected to run the code that creates visual effect on the LEDs.

I was wondering if I could let arduino powered up at all time and attach a switch to one of the analog pins This way when the switch is on and voltage on the analog pin changes to high then the Codes that runs the LED will run.

I guess this should be some sort of "if clause" to check the status of the analog pin to run the main code that runs the LEDs ,when the switch is on and the voltage is high.

how do I do that?
could you give me an example.
thanks

I guess I did it
Here is the code:

#include "FastLED.h"
#define NUM_LEDS 12
CRGB leds[NUM_LEDS];
#define PIN 7

void setup()
{
FastLED.addLeds<WS2812, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

// *** REPLACE FROM HERE ***
void loop() {
// colorWipe(0x00,0xff,0x00, 50);
//colorWipe(0x00,0x00,0xff, 50);
// colorWipe(0xff,0x00,0x00, 50);
// colorWipe(0x0f,0xff,0x0f, 50);
//colorWipe(0,255,50, 50);
// colorWipe(0xff,0x24,0xf8, 50);
colorWipe(0xe9,0xff,0x21, 50);
colorWipe(0,255,255, 255);
// colorWipe(0x1f,0x0f,0xff, 50);
// colorWipe(0x12,0xff,0x88, 50);
//colorWipe(0xff,0xff,0xff, 50);
}

void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {
if (digitalRead(9)) {
for(int i = 0; i < (NUM_LEDS / 2) + 1; i++) {
setPixel(i, red, red, red);
setPixel(NUM_LEDS - i, red, red, red);
showStrip();
delay(150);
}
} else {
setAll(0x00, 0x00, 0x00);
}
}
// *** REPLACE TO HERE ***

void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}

void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}

void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}

“I was wondering if I could let arduino powered up at all time. . .”

Yes

But, how is this a problem? If we are talking about 6 seconds, surely this isn’t earth shattering ;).

Have you heard about ISP programming your Arduino?

It would be better to use a digital input if you have one available.

const byte switchPin = /* whatever pin is available */;

void setup()
{
  pinMode(switchPin, INPUT_PULLUP);
  
  // rest of setup
}

void loop()
{
  if (digitalRead(switchPin) == HIGH)
  {
      // turn all LEDs off
  }
  else
  {
     // Codes that runs the LED
  }
}

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.

Please post your code.

Look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Tom... :slight_smile:

ToddL1962:
It would be better to use a digital input if you have one available.

Don't really see how that would make any difference, have not checked the data sheet, but a digital read of an analog pin shouldn't be any slower than a digital pin.

I'm not convinced the bootloader is the cause of the delay, on power-up the bootloader should go straight to the sketch, only on reset does it delay to watch for the programmer on the serial line.

david_2018:
Don't really see how that would make any difference, have not checked the data sheet, but a digital read of an analog pin shouldn't be any slower than a digital pin.

Indeed, "analog" pins are just digital pins that happen to be connected to the ADC multiplexer as well.
digitalRead on an "analog" pin is exactly the same as on any other digital pin.

david_2018:
I'm not convinced the bootloader is the cause of the delay, on power-up the bootloader should go straight to the sketch, only on reset does it delay to watch for the programmer on the serial line.

This is indeed true for the modern official Arduino bootloader, but older or Chinese bootloaders may not be as sophisticated.

You can download and flash the official bootloader to make sure the bootloader isn't the problem. You can also compile the bootloader from source and configure the delay yourself.

That being said, I'd also suspect OP's code rather than the bootloader.

Pieter

If you really want to get rid of that delay, program the Arduino using ICSP which will overwrite the bootloader. Only disadvantage is that you will always have to use ICSP to upload either the bootloader or a new sketch.

There are Arduinos that skip the bootloader at power up; if you currently use an Uno, you can consider a Leonardo.

Hi,
I think we need to see the OPs code.
A 6 second delay on power up is way too long.

Tom.... :slight_smile:

Hello
6 seconds is too long since I want to used it on my car stop light.

Saeidans:
Hello
6 seconds is too long since I want to used it on my car stop light.

Keep the Arduino permanently powered. Detect when the break pedal is activated and take action based on that.

Hi,
Can you please post your complete code.
Until we see your code we cannot give you any possibly accurate solutions.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

If your code is too big then attach it to your post as an ino file.

Thanks.. Tom... :slight_smile:

Saeidans:
6 seconds is too long since I want to used it on my car stop light.

That's ridiculous. Why is the processor powered off between stops? I think there's a fundamental flaw in the design of the code you haven't shown us.

Hello
I am using an Arduino nano to control smart LED to be used for tailgate stop light in my car.
the issue is there is about 6~7 seconds delay when I hit the break on the car where the LEDs should turn on instantly.

my question is how to eliminate the booting delay time?

Arrange the hardware and code so that the processor doesn't have to boot every time you hit the brake.

my question is how to eliminate the booting delay time?

Do you think that it might help if you posted your code and a schematic ?

Why does the Arduino need to boot when you press the brake pedal ?

larryd:
“I was wondering if I could let arduino powered up at all time. . .”

Yes

But, how is this a problem? If we are talking about 6 seconds, surely this isn’t earth shattering ;).

Have you heard about ISP programming your Arduino?

What is ISP program ? and how does it make a difference?
thanks

larryd:
“I was wondering if I could let arduino powered up at all time. . .”

Yes

But, how is this a problem? If we are talking about 6 seconds, surely this isn’t earth shattering ;).

Have you heard about ISP programming your Arduino?

What is ISP program ? and how does it make a difference?
thanks

ToddL1962:
It would be better to use a digital input if you have one available.

const byte switchPin = /* whatever pin is available */;

void setup()
{
 pinMode(switchPin, INPUT_PULLUP);
 
 // rest of setup
}

void loop()
{
 if (digitalRead(switchPin) == HIGH)
 {
     // turn all LEDs off
 }
 else
 {
    // Codes that runs the LED
 }
}

if (digitalRead(9)) {
for(int i = 0; i < (NUM_LEDS / 2) + 1; i++) {
setPixel(i, red, red, red);
setPixel(NUM_LEDS - i, red, red, red);
showStrip();
delay(150);

is this correct?

When the boot loader is removed, the time ‘it’ takes is no longer needed at power up.

Note you can use this method to replace the bootloader later if needed.

Duplicate post to here: if condition and Analog pin to eliminate boot load time - Programming Questions - Arduino Forum
Reported to moderator.

And, you STILL haven't told us why the board needs to be re-booted every time you hit the brake pedal.

Sounds like the power supply is getting shorted out, causing a reset. Wiring problem.