Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- // THIS IS THE GROUPS THAT I WANT TO BE SET. SAY RAILA AND RAILB ARE GOING TO BE SET TO THE SAME HUE. THEN I WANT TO SET A DEFAULT // HUE FOR THE CAPS. SO WHEN I TURN THE POT, IT STARTS AT A DIFFERENT POINT IN THE SPECTRUM.
- #include "FastLED.h"
- #define DATA_PIN 5
- #define Color_ORDER GRB
- #define LED_TYPE WS2812B
- #define NUM_LEDS 51
- //default brightness
- uint8_t max_bright = 255;
- CRGB leds[NUM_LEDS];
- //amount of leds in each group
- #define NUM_RAILA 24
- #define NUM_RAILB 21
- #define NUM_CAPS 6
- //pixel index naming and adding individual pixels to the custom group
- uint8_t raila[NUM_RAILA] = {0,1,2,7,8,9,14,15,16,20,21,22,27,28,29,34,35,36,41,42,43,48,49,50 };
- uint8_t railb[NUM_RAILB] = {4,5,6,10,11,12,17,18,19,24,25,26,31,32,33,38,39,40,45,46,47 };
- uint8_t caps[NUM_CAPS] = {3,13,23,30,37,44 };
- void setup() {
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- FastLED.setBrightness(max_bright);
- }
- // THIS IS JUST THE LAST COLOR THE GROUPS WERE SET TO. I WANT THEM TO BE HSV NOT CRGB
- void loop ()
- {
- //sets a color to the individual raila sections
- for (int i = 0; i < NUM_RAILA; i++)
- leds[raila[i]] = CRGB(255,89,0);
- //sets a color to the individual railb sections
- for (int i = 0; i < NUM_RAILB; i++)
- leds[railb[i]] = CRGB::Yellow;
- //sets a color to the caps
- for (int i = 0; i < NUM_CAPS; i++)
- leds[caps[i]] = CRGB::Red;
- FastLED.show();
- }
- //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
- // THIS IS THE POTENTIOMETER SKETCH THAT MARK MILLER POSTED ON HIS GITHUB PAGE. IM TRYING TO WORK THIS IN WITH MY GROUP PROJECT,
- // BUT I AM NOT A PROGRAMMER. I DONT KNOW WHAT IS NEEDED TO SET A HUE TO BE DIFFERENT DEFAULTS THAN THE OTHERS
- //===============================================================
- // hue_and_brightness_example.ino
- //
- // Example setup for using two potentiometers to control hue and
- // brightness with FastLED.
- //
- // Every time the function checkKnobs() is called it will read
- // the current value of both potentiometers and map those values
- // to a hue and master brightness for FastLED.
- //===============================================================
- #include "FastLED.h"
- #define LED_TYPE WS2812B
- #define DATA_PIN 13
- #define NUM_LEDS 51
- #define MASTER_BRIGHTNESS 255 // Set the master brigtness value [should be greater then min_brightness value].
- uint8_t min_brightness = 10; // Set a minimum brightness level.
- uint8_t brightness; // Mapped master brightness based on potentiometer reading.
- CRGB leds[NUM_LEDS];
- int potPinA = A1; // Pin for potentiometer A (for hue)
- int potPinB = A0; // Pin for potentiometer B (for brightness)
- int potValA; // Variable to store potentiometer A value (for hue)
- int potValB; // Variable to store potentiometer B value (for brightness)
- uint8_t hue; // Hue color (0-255)
- //---------------------------------------------------------------
- void setup() {
- delay(500); // Power-up delay
- //Serial.begin(115200); // Allows serial monitor output (check baud rate)
- FastLED.addLeds<LED_TYPE,DATA_PIN>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- FastLED.setBrightness(MASTER_BRIGHTNESS); // Initially set the max brightness. Will continuously update it later.
- pinMode(potPinA, INPUT); // Set pin as an input.
- pinMode(potPinB, INPUT); // Set pin as an input.
- }
- //---------------------------------------------------------------
- void loop() {
- checkKnobs(); // Call function to check knob positions.
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i] = CHSV(hue, 255, 255); // hue comes from pot A, and brightness value is scaled based on pot B.
- }
- FastLED.show();
- }
- //===============================================================
- void checkKnobs(){
- potValA = analogRead(potPinA); // Read potentiometer A (for hue).
- //potValA = map(potValA, 1023, 0, 0, 1023); // Reverse reading if potentiometer is wired backwards.
- hue = map(potValA, 0, 1023, 0, 255); // map(value, fromLow, fromHigh, toLow, toHigh)
- potValB = analogRead(potPinB); // Read potentiometer B (for brightness).
- brightness = map(potValB, 0, 1023, min_brightness, MASTER_BRIGHTNESS);
- // Map value between min_brightness and MASTER brightness values.
- // Note: We are limiting the lowest possible brightness value to the
- // min_brightness value assigned up top.
- FastLED.setBrightness(brightness); // Set master brightness based on potentiometer position.
- //Serial.print(" pot A: "); Serial.print(potValA); Serial.print(" hue: "); Serial.print(hue);
- //Serial.print(" pot B: "); Serial.print(potValB); Serial.print(" brightness: "); Serial.println(brightness);
- }
- //---------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement