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();
}