Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // noise8
- //
- // By: Andrew Tuline
- //
- // Date: Oct, 2014
- //
- // This is uses a FastLED noise generator.
- //
- // FastLED 2.1 is available at https://github.com/FastLED/FastLED/tree/FastLED2.1
- //
- #include <FastLED.h> // FastLED library
- #include "Button.h" // Button library. Includes press, long press, double press detection.
- // Pushbutton setup stuff
- const int buttonPin = 6; // Digital pin used for debounced pushbutton
- // int buttonState = 0;
- // int lastButtonState = 0;
- Button myBtn(buttonPin, true, true, 50); // Declare the button
- // Analog port setup stuff
- int aPin0 = 0; int aPin1 = 1; int aPin2 = 2; int aPin3 = 3; int aPin4 = 4; int aPin5 = 5;
- int aVal0 = 0; int aVal1 = 0; int aVal2 = 0; int aVal3 = 0; int aVal4 = 0; int aVal5 = 0;
- #define LED_DT 12 // Data pin
- #define NUM_LEDS 30 // Number of LED's
- #define COLOR_ORDER GRB // Change the order as necessary
- #define LED_TYPE WS2811 // What kind of strip are you using?
- #define BRIGHTNESS 128 // How bright do we want to go
- struct CRGB leds[NUM_LEDS]; // Initializxe our array
- // Initialize global variables for sequences
- int thisdelay = 40; // A delay value for the sequence(s)
- uint32_t x,v_time,hue_time;
- int hxy = 12630;
- uint8_t octaves=3;
- uint8_t hue_octaves=2;
- int xscale=30;
- int hue_scale=8;
- int hue_speed=5;
- int x_speed=25;
- int hxyinc = 10;
- void setup() {
- Serial.begin(57600);
- LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- random16_set_seed(1632); // Awesome randomizer
- random16_add_entropy(analogRead(6));
- FastLED.setBrightness(BRIGHTNESS);
- set_max_power_in_volts_and_milliamps(5, 500); // FastLED 2.1 Power management set at 5V, 500mA
- } // setup()
- void loop() {
- readbuttons();
- readpots();
- mynoise();
- show_at_max_brightness_for_power();
- delay_at_max_brightness_for_power(thisdelay*2.5);
- // Serial.println(LEDS.getFPS());
- } // loop()
- void mynoise() {
- fill_noise8(leds, NUM_LEDS, octaves, x, xscale, hue_octaves, hxy, hue_scale, hue_time);
- x += x_speed; // It's either moving or not
- hue_time += hue_speed;
- hxy += hxyinc;
- } // mynoise()
- void ChangeMe() {
- uint8_t secondHand = (millis() / 1000)%20 ; // Increase this if you want a longer demo. Currently changes once per minute.
- static uint8_t lastSecond = 99; // Static variable, means it's only defined once. This is our 'debounce' variable.
- if( lastSecond != secondHand) {
- lastSecond = secondHand;
- // if (secondHand == 0) {hue_scale =2000; octaves=3; hue_octaves=5; hue_speed=10;xscale=100; hxy = 5000;}
- if (secondHand == 10) {}
- if (secondHand == 30) {}
- if (secondHand == 40) {}
- if (secondHand == 50) {}
- }
- } // ChangeMe()
- void readpots() {
- // calculated:: x, hue_time, hxy
- // fixed:: octaves (1,5), xscale(), hue_octaves(1,5), hue_scale(1,20), hxyinc(1, 50), thisdelay(0, 100)
- aVal0 = map(analogRead(aPin0), 0, 1023, 1, 5);
- aVal1 = map(analogRead(aPin1), 0, 1023, 0, 1023);
- aVal2 = map(analogRead(aPin2), 0, 1023, 0, 5);
- aVal3 = map(analogRead(aPin3), 0, 1023, 0, 20);
- aVal4 = map(analogRead(aPin4), 0, 1023, 0, 50);
- aVal5 = map(analogRead(aPin5), 0, 1023, 0, 100);
- octaves = aVal0;
- xscale = aVal1;
- hue_octaves = aVal2;
- hue_scale = aVal3 * 16;
- hxyinc = aVal4;
- thisdelay = aVal5;
- }
- void readbuttons() { // Read the button and increase the mode
- myBtn.read();
- if(myBtn.wasReleased()) {
- // Change modes here
- }
- if(myBtn.pressedFor(1000)) {
- // You can reset here
- }
- } // readbutton()
- /*
- uint32_t x,v_time,hue_time;
- int hxy = 12630;
- uint8_t octaves=3;
- uint8_t hue_octaves=2;
- int xscale=30;
- int hue_scale=8;
- int hue_speed=5;
- int x_speed=25;
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement