atuline

FastLED Noise8 Pots

Jul 20th, 2015
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.28 KB | None | 0 0
  1.  
  2. // noise8
  3. //
  4. // By: Andrew Tuline
  5. //
  6. // Date: Oct, 2014
  7. //
  8. // This is uses a FastLED noise generator.
  9. //
  10. // FastLED 2.1 is available at https://github.com/FastLED/FastLED/tree/FastLED2.1
  11. //
  12.  
  13.  
  14. #include <FastLED.h>                                          // FastLED library
  15. #include "Button.h"                                           // Button library. Includes press, long press, double press detection.
  16.  
  17.  
  18. // Pushbutton setup stuff
  19. const int buttonPin = 6;                                      // Digital pin used for debounced pushbutton
  20. // int buttonState = 0;
  21. // int lastButtonState = 0;
  22. Button myBtn(buttonPin, true, true, 50);                      // Declare the button
  23.  
  24. // Analog port setup stuff
  25. int aPin0 = 0; int aPin1 = 1; int aPin2 = 2; int aPin3 = 3; int aPin4 = 4; int aPin5 = 5;
  26. int aVal0 = 0; int aVal1 = 0; int aVal2 = 0; int aVal3 = 0; int aVal4 = 0; int aVal5 = 0;
  27.  
  28.  
  29. #define LED_DT 12                                             // Data pin
  30. #define NUM_LEDS 30                                          // Number of LED's
  31. #define COLOR_ORDER GRB                                       // Change the order as necessary
  32. #define LED_TYPE WS2811                                       // What kind of strip are you using?
  33. #define BRIGHTNESS  128                                       // How bright do we want to go
  34.  
  35. struct CRGB leds[NUM_LEDS];                                   // Initializxe our array
  36.  
  37.  
  38. // Initialize global variables for sequences
  39. int thisdelay = 40;                                           // A delay value for the sequence(s)
  40.  
  41. uint32_t x,v_time,hue_time;
  42. int hxy = 12630;
  43. uint8_t octaves=3;
  44. uint8_t hue_octaves=2;
  45. int xscale=30;
  46. int hue_scale=8;
  47. int hue_speed=5;
  48. int x_speed=25;
  49. int hxyinc = 10;
  50.  
  51.  
  52. void setup() {
  53.   Serial.begin(57600);
  54.   LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  55.  
  56.   random16_set_seed(1632);                                     // Awesome randomizer
  57.   random16_add_entropy(analogRead(6));
  58.  
  59.   FastLED.setBrightness(BRIGHTNESS);
  60.   set_max_power_in_volts_and_milliamps(5, 500);               // FastLED 2.1 Power management set at 5V, 500mA
  61. } // setup()
  62.  
  63.  
  64. void loop() {
  65.   readbuttons();
  66.   readpots();
  67.   mynoise();
  68.   show_at_max_brightness_for_power();
  69.   delay_at_max_brightness_for_power(thisdelay*2.5);
  70. //  Serial.println(LEDS.getFPS());
  71. } // loop()
  72.  
  73.  
  74. void mynoise() {
  75.   fill_noise8(leds, NUM_LEDS, octaves, x, xscale, hue_octaves, hxy, hue_scale, hue_time);
  76.   x += x_speed;                              // It's either moving or not
  77.   hue_time += hue_speed;
  78.   hxy += hxyinc;
  79. } // mynoise()
  80.  
  81.  
  82.  
  83.  
  84.  
  85. void ChangeMe() {
  86.   uint8_t secondHand = (millis() / 1000)%20 ;                 // Increase this if you want a longer demo. Currently changes once per minute.
  87.   static uint8_t lastSecond = 99;                             // Static variable, means it's only defined once. This is our 'debounce' variable.
  88.  
  89.   if( lastSecond != secondHand) {
  90.     lastSecond = secondHand;
  91. //    if (secondHand == 0)   {hue_scale =2000; octaves=3; hue_octaves=5; hue_speed=10;xscale=100; hxy = 5000;}
  92.     if (secondHand == 10)  {}
  93.     if (secondHand == 30)  {}
  94.     if (secondHand == 40)  {}
  95.     if (secondHand == 50)  {}
  96.   }
  97.  
  98. } // ChangeMe()
  99.  
  100.  
  101. void readpots() {
  102.  
  103.   // calculated::      x, hue_time, hxy
  104.   // fixed::    octaves (1,5), xscale(), hue_octaves(1,5), hue_scale(1,20), hxyinc(1, 50), thisdelay(0, 100)
  105.  
  106.   aVal0 = map(analogRead(aPin0), 0, 1023, 1, 5);
  107.   aVal1 = map(analogRead(aPin1), 0, 1023, 0, 1023);
  108.   aVal2 = map(analogRead(aPin2), 0, 1023, 0, 5);
  109.   aVal3 = map(analogRead(aPin3), 0, 1023, 0, 20);
  110.   aVal4 = map(analogRead(aPin4), 0, 1023, 0, 50);
  111.   aVal5 = map(analogRead(aPin5), 0, 1023, 0, 100);
  112.  
  113.  
  114.   octaves = aVal0;
  115.   xscale = aVal1;
  116.   hue_octaves = aVal2;
  117.   hue_scale = aVal3 * 16;
  118.   hxyinc = aVal4;
  119.   thisdelay = aVal5;
  120.  
  121. }
  122.  
  123. void readbuttons() {                                            // Read the button and increase the mode
  124.   myBtn.read();
  125.   if(myBtn.wasReleased()) {
  126.     // Change modes here
  127.   }
  128.   if(myBtn.pressedFor(1000)) {
  129.     // You can reset here
  130.   }
  131. } // readbutton()
  132.  
  133.  
  134.  
  135. /*
  136.  
  137. uint32_t x,v_time,hue_time;
  138. int hxy = 12630;
  139. uint8_t octaves=3;
  140. uint8_t hue_octaves=2;
  141. int xscale=30;
  142. int hue_scale=8;
  143. int hue_speed=5;
  144. int x_speed=25;
  145.  
  146. */
Advertisement
Add Comment
Please, Sign In to add comment