Hello.
I would like to use a button pressed to change the mode between my Adafruit RGB LED Wire from flashing, to off, and back with the click of a button. I have put a button onto my Arduino and connected it to pin 7. Here is an example of the "flashing" code.
In the code, Black means off.
Thank you!
#include "FastLED.h" // library for LED's to work.
#define NUM_LEDS 60
#define DATA_PIN 6
int val; // the value of the potentiometer.
int potpin = 0; // potentiometer output.
int elPin = 13; // pin for EL Wir.
CRGB leds[NUM_LEDS]; // Defines the array of leds
void setup() {
;
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);// imports code from library and uses it to control 60 LED's controlled by pin 6.
pinMode(elPin, OUTPUT); // sets output for pin 13 (EL Wire)
}
void loop() {
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 500, 5); // maps the value
for (int x = 0; x < NUM_LEDS ; x++) //defines number of LED's
{
leds[x] = CRGB::White; // changes LED color to white
}
FastLED.show();
delay(val); //value of delay is the value of the potentiometer
{
for (int x = 0; x < NUM_LEDS ; x++) //defines number of LED's
{
leds[x] = CRGB::Black; // changed LED color to black AKA off
}
FastLED.show();//shows
delay(val);//value of delay is the value of the potentiometer
}
}
{
{
digitalWrite(elPin, HIGH); // EL Wire is synced with LED wire
}
}
}