I think I am going at this the wrong way. It's hard to tell so I was hoping I could get some guidance.
I am trying to create a code that has NEOPIXELS flicker like stars and then have a random LED sparkle.
it's still an early attempt so my code isn't the greatest. I have a feeling I am going at this wrong so before I go any further i wanted to check.
Code: Select all
#include "Adafruit_NeoPixel.h"
//define pins and LEDs
#define LED_PIN 1
#define TOUCH_PIN 2
#define N_LEDS 6
#define BRIGHTNESS 80
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(N_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pixels.begin();
//define initial brightness
pixels.setBrightness(BRIGHTNESS);
pixels.show();
}
void loop() {
//setting random variables
//choose a random LED (one that was not choosen before -an array?)
uint8_t ranLED = random(0,(N_LEDS-1));
//random brightness
uint8_t ranFlickerBrightness = random(100,120);
//brightness counter for increment counting
uint8_t brightCounter = 2;
//leds randomly trigger
uint8_t randDelay = random(100,500);
//get the state of LEDS, are they all back to initial? for other functions to work.
//add random 'flicker'
//increase a random LED to 'shine' increase in exponential increments
for(int i=1;i<(ranFlickerBrightness*2);i++){
if (brightCounter <= ranFlickerBrightness){
brightCounter = brightCounter + 1;
pixels.setPixelColor(ranLED, BRIGHTNESS+brightCounter, BRIGHTNESS+brightCounter, BRIGHTNESS+brightCounter );
}
else{
brightCounter = brightCounter - 1;
pixels.setPixelColor(ranLED, BRIGHTNESS+brightCounter, BRIGHTNESS+brightCounter, BRIGHTNESS+brightCounter );
}
//increase/decrease rapidly
brightCounter*=brightCounter;
}
//do I really want to work with a delay?
delay(randDelay);
pixels.show();
}
//other functions will be added.
edit: hit enter too fast.