Advertisement
atuline

FastLED power management test

Oct 29th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. /* Rainbow March
  2.  
  3. By: Andrew Tuline
  4.  
  5. Date: Oct, 2014
  6.  
  7. Rainbow marching up the strand. Pretty basic, but oh so popular.
  8.  
  9. In this sketch, I vary the max_bright value to determine the point at which LED's start blinking
  10. when using set_max_power_in_volts_and_milliamps() and show_at_max_brightness_for_power()
  11.  
  12. I'm using an Arduino powered by USB and a couple of 16850 batteries. A strand of 15 WS2812B LED's is powered by the Arduino 5V output.
  13.  
  14. The accompanying video is at http://youtu.be/JwO5ZyhWWHw
  15.  
  16. Table contains max_bright values at which point the LED's start blinking.
  17.  
  18. Defined
  19. # LEDS ----------------Defined mA------------------------
  20. 100 200 500 1000 2000
  21.  
  22. 25 58 125 n/a n/a n/a
  23. 50 27 55 148 n/a n/a
  24. 100 9 28 76 145 n/a
  25. 150 8 19 49 100 199
  26. 200 - 14 37 80 155
  27.  
  28.  
  29. FastLED is available at https://github.com/FastLED/FastLED
  30.  
  31. */
  32.  
  33.  
  34. #include <FastLED.h> // FastLED library
  35.  
  36. #define LED_DT 13 // Data pin
  37. #define NUM_LEDS 50 // Number of LED's
  38. #define COLOR_ORDER GRB // Change the order as necessary
  39. #define LED_TYPE WS2811 // What kind of strip are you using?
  40.  
  41. uint8_t max_bright = 255; // How bright do we want to go
  42.  
  43. struct CRGB leds[NUM_LEDS]; // Initialize our array
  44.  
  45.  
  46. // Initialize global variables for sequences
  47. uint8_t thisdelay = 8; // A delay value for the sequence(s)
  48. uint8_t thishue = 0; // Starting hue value.
  49. uint8_t thisdelta = 1; // Delta hue change between pixels
  50. int8_t thisrot = 1; // Hue rotation speed.
  51. uint8_t thisdir = 0; // Hue rotation direction.
  52.  
  53.  
  54.  
  55. void setup() {
  56. Serial.begin(57600);
  57. LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS);
  58. FastLED.setBrightness(max_bright); // FastLED brightness limiter
  59. set_max_power_in_volts_and_milliamps(5, 200); // FastLED 2.1 Power management set at 5V, 500mA
  60. } // setup()
  61.  
  62.  
  63.  
  64. void loop () {
  65. rainbow_march();
  66. show_at_max_brightness_for_power();
  67. delay_at_max_brightness_for_power(thisdelay*2.5);
  68.  
  69. uint8_t potval = map(analogRead(A4), 0, 1023, 0, 255);
  70. Serial.println(potval);
  71. FastLED.setBrightness(potval); // FastLED brightness limiter
  72. } // loop()
  73.  
  74.  
  75.  
  76. void rainbow_march() { // The fill_rainbow call doesn't support brightness levels
  77. if(thisdir == 0) thishue += thisrot; else thishue -= thisrot;
  78. fill_rainbow( leds, NUM_LEDS, thishue, thisdelta );
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement