Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #include <Adafruit_NeoPixel.h>
- #define NUM_LEDS 32
- #define DATA_PIN 2
- #define CIELPWM(a) (pgm_read_word_near(CIEL8 + a)) // CIE Lightness loopup table
- #ifdef __AVR__
- #include <avr/power.h>
- #endif
- CRGB leds[NUM_LEDS];
- uint8_t ledctr = 0;
- int vals[] = {
- 0, 1, 2, 3, 4, 5, 7, 9, 12,
- 15, 18, 22, 27, 32, 38, 44, 51, 58,
- 67, 76, 86, 96, 108, 120, 134, 148, 163,
- 180, 197, 216, 235, 255
- };
- void setup() {
- // put your setup code here, to run once:
- // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
- #if defined (__AVR_ATtiny85__)
- if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
- #endif
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- //leds[NUM_LEDS-1].g = 2;
- }
- void loop() {
- // put your main code here, to run repeatedly:
- FadeUp()2;
- }
- void FadeUp(){
- if(leds[NUM_LEDS - 1].g < 255)
- {
- leds[NUM_LEDS - 1].g = (leds[NUM_LEDS - 1].g + 1)*2;
- if(leds[NUM_LEDS - 1].g > 255)
- {
- leds[NUM_LEDS - 1].g = 255;
- }
- }
- for(int i = NUM_LEDS - 2; i>=0; i--)
- {
- if(leds[i+1].g > 2 && leds[i].g < 255)
- {
- leds[i].g = (leds[i].g + 1)*2;
- if(leds[i].g > 255)
- {
- leds[i].g = 255;
- }
- }
- }
- FastLED.show();
- FastLED.delay(60);
- }
- void FadeUp2(){
- if(leds[NUM_LEDS - 1].g < 255)
- {
- leds[NUM_LEDS - 1].g = vals[FindIndex(leds[NUM_LEDS - 1].g) + 1];
- /*
- if(leds[NUM_LEDS - 1].g > 255)
- {
- leds[NUM_LEDS - 1].g = 255;
- }
- */
- }
- for(int i = NUM_LEDS - 2; i>=0; i--)
- {
- if(leds[i+1].g > 3 && leds[i].g < 255)
- {
- leds[i].g = vals[FindIndex(leds[i].g) + 1];
- /*
- if(leds[i].g > 255)
- {
- leds[i].g = 255;
- }
- */
- }
- }
- FastLED.show();
- FastLED.delay(60);
- }
- int FindIndex(int val){
- for(int i=0; i < 32; i++){
- if(val == vals[i]){
- return i;
- break;
- }
- }
- }
- /*
- void FadeUp2(){
- for(int i = 0; i<NUM_LEDS - 1; i++)
- {
- //set yourself to the color of the one above you and increment the one above you
- if(leds[i].g < 255){
- leds[i] = leds[i+1];
- leds[i+1].g += 1;
- }
- }
- FastLED.show();
- delay(25);
- }
- void newFade() {
- for (int i=0; i<NUM_LEDS; i++) {
- leds[ledctr].g = pow(2,i)-1;
- FastLED.show();
- }
- if (ledctr++ > NUM_LEDS-1) {
- ledctr = 0;
- FastLED.clear();
- }
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement