Advertisement
Guest User

Pollo

a guest
May 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <FastLED.h>
  2.  
  3.  
  4. #define LED_PIN 3              // which pin are LEDS connected to?
  5. #define NUM_LEDS 32
  6. #define COLOR_ORDER RGB
  7. #define LED_TYPE WS2812B        // i'm using WS2811s, FastLED supports lots of different types.
  8. #define RB 5
  9. /*
  10.  set your desired minimum and maxium brigtness settings here.
  11.  Valid values are 0 - 255
  12.  With 0 being fully dim, or not lit, and 255 being fully on.
  13.  Therefore half power, or 50%, would be 128
  14.  */
  15.  
  16. #define MAX_BRIGHTNESS 255      // Thats full on, watch the power!
  17. #define MIN_BRIGHTNESS 64       // set to a minimum of 25%
  18.  
  19. //const int brightnessInPin = A0;  // The Analog input pin that the brightness control potentiometer is attached to.
  20. //const int speedInPin = A1;       // Analog input pin that the speed control potentiometer is attached to.
  21. const int colourInPin = A2;      // The Analog input pin that the colour control potentiometer is attached to.
  22.  
  23. struct CRGB leds[NUM_LEDS];
  24.  
  25. void setup() {
  26.   delay(500); // in case we do something stupid. We dont want to get locked out.
  27.   pinMode(RB, INPUT );
  28.  
  29.   LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  30.   FastLED.setBrightness(MAX_BRIGHTNESS);
  31. }
  32.  
  33. void loop() {
  34.   // read the analog brightness value:
  35.   //int brightValue = analogRead(brightnessInPin);            
  36.   // map it to the range of the FastLED brightness:
  37.   int mappedValue = 1;
  38. int rb2 = digitalRead(RB);
  39.   /*
  40.    At this point, brightness could be full off (mappedValue == 0)
  41.    or it could be fully on (mappedValue == 255).
  42.    if you are ruuning from a battery pack, or in a dark room, you
  43.    may not want full brightness.
  44.    Or if you are in daylight, you may not want the pixels to go out.
  45.    the following code, checks if mappedValue is above or below our defined
  46.    brightness settings above.
  47.    It works like this.
  48.    
  49.    we get mappedValue: if mappedValue is between MIN_BRIGHTNESS and MAX_BRIGHTNESS.
  50.    we get MIN_BRIGHTNESS: if mappedValue is less than our defined MIN_BRIGHTNESS.
  51.    we get MAX_BRIGHTNESS: if mappedValue is greater than our defined MAX_BRIGHTNESS
  52.    
  53.    so, it limits range of brightness values.
  54.    
  55.    */
  56.  
  57.   //int outputValue = constrain(mappedValue, MIN_BRIGHTNESS, MAX_BRIGHTNESS);
  58.  
  59.   // now we set the brightness of the strip
  60.   FastLED.setBrightness(constrain(mappedValue, MIN_BRIGHTNESS, MAX_BRIGHTNESS));
  61.  
  62.   // read the analog speed value:          
  63.   // map it to a value used in delay();
  64.   int delayValue = 500;  
  65.  
  66.   int mappedHue;
  67.   // read the analog brightness value:
  68.   //int hueValue = analogRead(colourInPin);            
  69.   // map it to the range of the FastLED brightness:
  70.  
  71. if(rb2){
  72.  
  73.   // First slide the led in one direction
  74.   for(int i = 0; i < NUM_LEDS; i++) {
  75.     mappedHue = map(analogRead(colourInPin), 0, 1023, 0, 255);
  76.     // Set the i'th led to the chosen colour
  77.     leds[i] = CHSV(mappedHue, 255, 255);
  78.     for(int i=0;i<NUM_LEDS;i++){
  79.       int perc= mappedHue+(mappedHue*i*100);
  80.       leds[i] = CHSV(mappedHue, 255, 255);
  81.     }
  82.     // Show the leds
  83.     FastLED.show();
  84.     // now that we've shown the leds, reset the i'th led to black
  85.     //leds[i] = CRGB::Black;
  86.     // Wait a little bit before we loop around and do it again
  87.     delay(delayValue);
  88. }}
  89. else{
  90. rainbowCycle(20);
  91. }
  92. }
  93. void rainbowCycle(int SpeedDelay) {
  94.   byte *c;
  95.   uint16_t i, j;
  96.  
  97.   for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
  98.     for(i=0; i< NUM_LEDS; i++) {
  99.       c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
  100.       setPixel(i, *c, *(c+1), *(c+2));
  101.     }
  102.     showStrip();
  103.     delay(SpeedDelay);
  104.   }
  105. }
  106.  
  107. byte * Wheel(byte WheelPos) {
  108.   static byte c[3];
  109.  
  110.   if(WheelPos < 85) {
  111.    c[0]=WheelPos * 3;
  112.    c[1]=255 - WheelPos * 3;
  113.    c[2]=0;
  114.   } else if(WheelPos < 170) {
  115.    WheelPos -= 85;
  116.    c[0]=255 - WheelPos * 3;
  117.    c[1]=0;
  118.    c[2]=WheelPos * 3;
  119.   } else {
  120.    WheelPos -= 170;
  121.    c[0]=0;
  122.    c[1]=WheelPos * 3;
  123.    c[2]=255 - WheelPos * 3;
  124.   }
  125.  
  126.   return c;
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement