Guest User

Three_sin_demo

a guest
Oct 22nd, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1.  
  2. /* three_sin demo
  3.  
  4. By: Andrew Tuline
  5.  
  6. Date: Oct, 2014
  7.  
  8. 3 sine waves, one for each colour. I'm already doing a lot with 2 sine waves, so I didn't take this far.
  9.  
  10. FastLED 2.1 is available at https://github.com/FastLED/FastLED/tree/FastLED2.1
  11.  
  12. Note: If you receive compile errors (as I have in the Stino add-on for Sublime Text), set the compiler to 'Full Compilation'.
  13.  
  14. */
  15.  
  16.  
  17. #include "FastLED.h" // FastLED library. Preferably the latest copy of FastLED 2.1.
  18.  
  19. // Fixed definitions cannot change on the fly.
  20. #define LED_DT 13 // Serial data pin for WS2812B or WS2801
  21. #define COLOR_ORDER GRB // Are they RGB, GRB or what??
  22. #define LED_TYPE WS2812B // What kind of strip are you using?
  23. #define NUM_LEDS 24 // Number of LED's
  24.  
  25. // Initialize changeable global variables.
  26. uint8_t max_bright = 255; // Overall brightness definition. It can be changed on the fly.
  27.  
  28. struct CRGB leds[NUM_LEDS]; // Initialize our LED array.
  29.  
  30.  
  31. // Initialize global variables for sequences
  32. uint8_t thisdelay = 8; // A delay value for the sequence(s)
  33.  
  34. int wave1=0;
  35. int wave2=0;
  36. int wave3=0;
  37.  
  38. uint8_t inc1 = 1;
  39. uint8_t inc2 = 1;
  40. uint8_t inc3 = -3;
  41.  
  42. uint8_t lvl1 = 80;
  43. uint8_t lvl2 = 80;
  44. uint8_t lvl3 = 80;
  45.  
  46. uint8_t mul1 = 20;
  47. uint8_t mul2 = 25;
  48. uint8_t mul3 = 22;
  49.  
  50.  
  51.  
  52. void setup() {
  53. Serial.begin(57600);
  54. LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  55. FastLED.setBrightness(max_bright);
  56. set_max_power_in_volts_and_milliamps(5, 500); // FastLED 2.1 Power management set at 5V, 500mA
  57.  
  58. random16_set_seed(4832); // Awesome randomizer (which we don't yet need here.)
  59. random16_add_entropy(analogRead(2));
  60.  
  61. } // setup()
  62.  
  63.  
  64.  
  65. void loop () {
  66. three_sin(); // Improved method of using non-blocking delay
  67. show_at_max_brightness_for_power(); // Power managed display of LED's
  68. delay_at_max_brightness_for_power(thisdelay*2.5);
  69. LEDS.countFPS();
  70. } // loop()
  71.  
  72.  
  73.  
  74. void three_sin() {
  75. wave1 += inc1;
  76. wave2 += inc2;
  77. wave3 += inc3;
  78. for (int k=0; k<NUM_LEDS; k++) {
  79. leds[k].r = qsub8(quadwave8(mul1*k + wave1), lvl1); // Another fixed frequency, variable phase sine wave with lowered level
  80. // leds[k].g = qsub8(quadwave8(mul2*k + wave2), lvl2); // A fixed frequency, variable phase sine wave with lowered level
  81. //leds[k].b = qsub8(quadwave8(mul3*k + wave3), lvl3); // A fixed frequency, variable phase sine wave with lowered level
  82. }
  83. } // three_sin()
Advertisement
Add Comment
Please, Sign In to add comment