Star Flicker - need redirection

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Dae
 
Posts: 25
Joined: Wed Oct 08, 2014 1:46 am

Star Flicker - need redirection

Post by Dae »

Hello Everyone,
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.
I will move the function out of the loop after i have it working and start making other adjustments like constructs and functions. I will be adding more to this later as noted in the code. Thank you for taking the time to look at this.
edit: hit enter too fast.

User avatar
Dae
 
Posts: 25
Joined: Wed Oct 08, 2014 1:46 am

Re: Star Flicker - need redirection

Post by Dae »

I noticed I made some errors so here is an updated version:

Code: Select all

#include "Adafruit_NeoPixel.h"

//define pins and leds
#define LED_PIN  1
#define TOUCH_PIN 2
#define N_LEDS  6 

#define INITIALBRIGHTNESS 40
boolean startup = true;

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(N_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
  pixels.show();
}
void loop() {
  //setting random variables
  //choose a random LED (one that was not chosen before -an array?)
  uint8_t ranLED = random(0,N_LEDS);
  //random shine limit
  uint8_t ranShineBrightness = random(100,120);
  //brightness counter for increment counting 
  uint8_t brightCounter = 2;
  //LEDs randomly trigger
  uint8_t randDelay = random(500,6000);
  
  //set initial brightness, this looks weird.
  if(startup == true){
    for(int count=1;count<=INITIALBRIGHTNESS;count++){
      for(int n=0;n<=N_LEDS;n=n+1){
        pixels.setPixelColor(n,count, count, count);
        pixels.show();
        delay(4);
      }
    }
    startup = false;
  }
  
  //get the state of LEDs, are they all back to initial?
  //add random 'flicker' function
  
  //increase a random LED to 'shine' increase in exponential increments
  for(int i=1;i<(ranShineBrightness*2);i++){

    //increase brightness
    if (i <= ranShineBrightness){
      pixels.setPixelColor(ranLED, INITIALBRIGHTNESS+brightCounter, INITIALBRIGHTNESS+brightCounter,  INITIALBRIGHTNESS+brightCounter );
      //increase rapidly
      brightCounter++;
    }
    //decrease brightness
    else{
      pixels.setPixelColor(ranLED, INITIALBRIGHTNESS+brightCounter, INITIALBRIGHTNESS+brightCounter,  INITIALBRIGHTNESS+brightCounter );
      //decrease rapidly
     brightCounter--;
    }
    pixels.show();
    delay(5);
  }
  //do I really want to work with a delay?
  delay(randDelay);
}
//future functions
Again, I am not sure if I am doing this right and now i am having an issue with my random delay.
It's late I'll sleep on it.
Thanks again for reading.

User avatar
Dae
 
Posts: 25
Joined: Wed Oct 08, 2014 1:46 am

Re: Star Flicker - need redirection

Post by Dae »

I sincerely hope I am not posting in the wrong section. :(
I would like someone o tell me if I am.

User avatar
Dae
 
Posts: 25
Joined: Wed Oct 08, 2014 1:46 am

Re: Star Flicker - need redirection

Post by Dae »

Uhm Hello?

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: Star Flicker - need redirection

Post by Franklin97355 »

I sincerely hope I am not posting in the wrong section. :(
No, you are in the right section it's just nobody has anything to say about it yet. Perhaps if you were to tell us what happens when you run the code and what you are trying to do to fix the problems you are having it would help get the conversation going. (By the way, your avatar is disturbing to me.)

User avatar
davidl13
 
Posts: 187
Joined: Fri Oct 25, 2013 10:51 pm

Re: Star Flicker - need redirection

Post by davidl13 »

franklin97355:(By the way, your avatar is disturbing to me.)
It ain't just you...

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”