Skip to content

Instantly share code, notes, and snippets.

@Robiv8
Created August 5, 2019 22:32
Show Gist options
  • Save Robiv8/5e68fd0c383a60b6d065a22d84bbb0ef to your computer and use it in GitHub Desktop.
Save Robiv8/5e68fd0c383a60b6d065a22d84bbb0ef to your computer and use it in GitHub Desktop.
Arduino Neopixel Auto Blinker
#include <FastLED.h>
// How many leds in your strip?
#define NUM_LEDS 46
// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806, define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 2
//#define CLOCK_PIN 13
int buttonPin = 4; // the number of the pushbutton pin
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
LEDS.addLeds<WS2812,DATA_PIN,GRB>(leds,NUM_LEDS);
LEDS.setBrightness(128);
pinMode(buttonPin, INPUT);
}
void fadeall() { for(int i = 0; i < NUM_LEDS; i++) { leds[i].nscale8(250); } }
void loop() {
int buttonState = digitalRead(buttonPin);
static uint8_t hue = 0;
for(int i = 0; i < NUM_LEDS; i++)
{
if(buttonState == HIGH) // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
// Set the i'th led to orange
leds[i] = CRGB(255, 130, 0);
// Show the leds
FastLED.show();
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
for(int i = 0; i < NUM_LEDS; i++)
{
if(buttonState == HIGH)
// Set the i'th led to black
leds[i] = CRGB(0, 0, 0);
// Show the leds
FastLED.show();
fadeall();
// Wait a little bit before we loop around and do it again
delay(10);
}
while(digitalRead(buttonPin) == LOW) // check if the pushbutton is pressed. If not, the buttonState is LOW:
{
//wait until the button is pressed again
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment