Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- #define LED_PIN 3 // which pin are LEDS connected to?
- #define NUM_LEDS 32
- #define COLOR_ORDER RGB
- #define LED_TYPE WS2812B // i'm using WS2811s, FastLED supports lots of different types.
- #define RB 5
- /*
- set your desired minimum and maxium brigtness settings here.
- Valid values are 0 - 255
- With 0 being fully dim, or not lit, and 255 being fully on.
- Therefore half power, or 50%, would be 128
- */
- #define MAX_BRIGHTNESS 255 // Thats full on, watch the power!
- #define MIN_BRIGHTNESS 64 // set to a minimum of 25%
- //const int brightnessInPin = A0; // The Analog input pin that the brightness control potentiometer is attached to.
- //const int speedInPin = A1; // Analog input pin that the speed control potentiometer is attached to.
- const int colourInPin = A2; // The Analog input pin that the colour control potentiometer is attached to.
- struct CRGB leds[NUM_LEDS];
- void setup() {
- delay(500); // in case we do something stupid. We dont want to get locked out.
- pinMode(RB, INPUT );
- LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(MAX_BRIGHTNESS);
- }
- void loop() {
- // read the analog brightness value:
- //int brightValue = analogRead(brightnessInPin);
- // map it to the range of the FastLED brightness:
- int mappedValue = 1;
- int rb2 = digitalRead(RB);
- /*
- At this point, brightness could be full off (mappedValue == 0)
- or it could be fully on (mappedValue == 255).
- if you are ruuning from a battery pack, or in a dark room, you
- may not want full brightness.
- Or if you are in daylight, you may not want the pixels to go out.
- the following code, checks if mappedValue is above or below our defined
- brightness settings above.
- It works like this.
- we get mappedValue: if mappedValue is between MIN_BRIGHTNESS and MAX_BRIGHTNESS.
- we get MIN_BRIGHTNESS: if mappedValue is less than our defined MIN_BRIGHTNESS.
- we get MAX_BRIGHTNESS: if mappedValue is greater than our defined MAX_BRIGHTNESS
- so, it limits range of brightness values.
- */
- //int outputValue = constrain(mappedValue, MIN_BRIGHTNESS, MAX_BRIGHTNESS);
- // now we set the brightness of the strip
- FastLED.setBrightness(constrain(mappedValue, MIN_BRIGHTNESS, MAX_BRIGHTNESS));
- // read the analog speed value:
- // map it to a value used in delay();
- int delayValue = 500;
- int mappedHue;
- // read the analog brightness value:
- //int hueValue = analogRead(colourInPin);
- // map it to the range of the FastLED brightness:
- if(rb2){
- // First slide the led in one direction
- for(int i = 0; i < NUM_LEDS; i++) {
- mappedHue = map(analogRead(colourInPin), 0, 1023, 0, 255);
- // Set the i'th led to the chosen colour
- leds[i] = CHSV(mappedHue, 255, 255);
- for(int i=0;i<NUM_LEDS;i++){
- int perc= mappedHue+(mappedHue*i*100);
- leds[i] = CHSV(mappedHue, 255, 255);
- }
- // Show the leds
- FastLED.show();
- // now that we've shown the leds, reset the i'th led to black
- //leds[i] = CRGB::Black;
- // Wait a little bit before we loop around and do it again
- delay(delayValue);
- }}
- else{
- rainbowCycle(20);
- }
- }
- void rainbowCycle(int SpeedDelay) {
- byte *c;
- uint16_t i, j;
- for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
- for(i=0; i< NUM_LEDS; i++) {
- c=Wheel(((i * 256 / NUM_LEDS) + j) & 255);
- setPixel(i, *c, *(c+1), *(c+2));
- }
- showStrip();
- delay(SpeedDelay);
- }
- }
- byte * Wheel(byte WheelPos) {
- static byte c[3];
- if(WheelPos < 85) {
- c[0]=WheelPos * 3;
- c[1]=255 - WheelPos * 3;
- c[2]=0;
- } else if(WheelPos < 170) {
- WheelPos -= 85;
- c[0]=255 - WheelPos * 3;
- c[1]=0;
- c[2]=WheelPos * 3;
- } else {
- WheelPos -= 170;
- c[0]=0;
- c[1]=WheelPos * 3;
- c[2]=255 - WheelPos * 3;
- }
- return c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement