Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #include <FastLED.h>
  2. #include <Adafruit_NeoPixel.h>
  3. #define NUM_LEDS 32
  4. #define DATA_PIN 2
  5. #define CIELPWM(a) (pgm_read_word_near(CIEL8 + a)) // CIE Lightness loopup table
  6. #ifdef __AVR__
  7. #include <avr/power.h>
  8. #endif
  9. CRGB leds[NUM_LEDS];
  10. uint8_t ledctr = 0;
  11. int vals[] = {
  12. 0, 1, 2, 3, 4, 5, 7, 9, 12,
  13. 15, 18, 22, 27, 32, 38, 44, 51, 58,
  14. 67, 76, 86, 96, 108, 120, 134, 148, 163,
  15. 180, 197, 216, 235, 255
  16. };
  17. void setup() {
  18. // put your setup code here, to run once:
  19. // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  20. #if defined (__AVR_ATtiny85__)
  21. if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  22. #endif
  23. FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  24. //leds[NUM_LEDS-1].g = 2;
  25.  
  26. }
  27.  
  28. void loop() {
  29. // put your main code here, to run repeatedly:
  30.  
  31. FadeUp()2;
  32.  
  33. }
  34.  
  35. void FadeUp(){
  36.  
  37. if(leds[NUM_LEDS - 1].g < 255)
  38. {
  39. leds[NUM_LEDS - 1].g = (leds[NUM_LEDS - 1].g + 1)*2;
  40. if(leds[NUM_LEDS - 1].g > 255)
  41. {
  42. leds[NUM_LEDS - 1].g = 255;
  43. }
  44. }
  45. for(int i = NUM_LEDS - 2; i>=0; i--)
  46. {
  47. if(leds[i+1].g > 2 && leds[i].g < 255)
  48. {
  49. leds[i].g = (leds[i].g + 1)*2;
  50. if(leds[i].g > 255)
  51. {
  52. leds[i].g = 255;
  53. }
  54. }
  55. }
  56.  
  57. FastLED.show();
  58. FastLED.delay(60);
  59. }
  60. void FadeUp2(){
  61.  
  62. if(leds[NUM_LEDS - 1].g < 255)
  63. {
  64. leds[NUM_LEDS - 1].g = vals[FindIndex(leds[NUM_LEDS - 1].g) + 1];
  65. /*
  66. if(leds[NUM_LEDS - 1].g > 255)
  67. {
  68. leds[NUM_LEDS - 1].g = 255;
  69. }
  70. */
  71. }
  72. for(int i = NUM_LEDS - 2; i>=0; i--)
  73. {
  74. if(leds[i+1].g > 3 && leds[i].g < 255)
  75. {
  76. leds[i].g = vals[FindIndex(leds[i].g) + 1];
  77. /*
  78. if(leds[i].g > 255)
  79. {
  80. leds[i].g = 255;
  81. }
  82. */
  83. }
  84. }
  85. FastLED.show();
  86. FastLED.delay(60);
  87. }
  88.  
  89. int FindIndex(int val){
  90. for(int i=0; i < 32; i++){
  91. if(val == vals[i]){
  92. return i;
  93. break;
  94. }
  95. }
  96. }
  97. /*
  98. void FadeUp2(){
  99. for(int i = 0; i<NUM_LEDS - 1; i++)
  100. {
  101. //set yourself to the color of the one above you and increment the one above you
  102. if(leds[i].g < 255){
  103. leds[i] = leds[i+1];
  104. leds[i+1].g += 1;
  105. }
  106. }
  107. FastLED.show();
  108. delay(25);
  109.  
  110. }
  111.  
  112. void newFade() {
  113.  
  114. for (int i=0; i<NUM_LEDS; i++) {
  115. leds[ledctr].g = pow(2,i)-1;
  116.  
  117. FastLED.show();
  118. }
  119.  
  120. if (ledctr++ > NUM_LEDS-1) {
  121. ledctr = 0;
  122. FastLED.clear();
  123. }
  124. }
  125. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement