Advertisement
Guest User

Untitled

a guest
Jun 17th, 2015
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  2. // 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.
  3.  
  4. #include "FastLED.h"
  5. #define DATA_PIN 5
  6. #define Color_ORDER GRB
  7. #define LED_TYPE WS2812B
  8. #define NUM_LEDS 51
  9. //default brightness
  10. uint8_t max_bright = 255;
  11. CRGB leds[NUM_LEDS];
  12.  
  13. //amount of leds in each group
  14. #define NUM_RAILA 24
  15. #define NUM_RAILB 21
  16. #define NUM_CAPS 6
  17. //pixel index naming and adding individual pixels to the custom group
  18. 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 };
  19. 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 };
  20. uint8_t caps[NUM_CAPS] = {3,13,23,30,37,44 };
  21.  
  22.  
  23. void setup() {
  24. FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  25. FastLED.setBrightness(max_bright);
  26. }
  27. // THIS IS JUST THE LAST COLOR THE GROUPS WERE SET TO. I WANT THEM TO BE HSV NOT CRGB
  28. void loop ()
  29. {
  30. //sets a color to the individual raila sections
  31. for (int i = 0; i < NUM_RAILA; i++)
  32. leds[raila[i]] = CRGB(255,89,0);
  33.  
  34. //sets a color to the individual railb sections
  35. for (int i = 0; i < NUM_RAILB; i++)
  36. leds[railb[i]] = CRGB::Yellow;
  37.  
  38. //sets a color to the caps
  39. for (int i = 0; i < NUM_CAPS; i++)
  40. leds[caps[i]] = CRGB::Red;
  41.  
  42.  
  43.  
  44.  
  45. FastLED.show();
  46. }
  47. //XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  48. // THIS IS THE POTENTIOMETER SKETCH THAT MARK MILLER POSTED ON HIS GITHUB PAGE. IM TRYING TO WORK THIS IN WITH MY GROUP PROJECT,
  49. // BUT I AM NOT A PROGRAMMER. I DONT KNOW WHAT IS NEEDED TO SET A HUE TO BE DIFFERENT DEFAULTS THAN THE OTHERS
  50.  
  51. //===============================================================
  52. // hue_and_brightness_example.ino
  53. //
  54. // Example setup for using two potentiometers to control hue and
  55. // brightness with FastLED.
  56. //
  57. // Every time the function checkKnobs() is called it will read
  58. // the current value of both potentiometers and map those values
  59. // to a hue and master brightness for FastLED.
  60. //===============================================================
  61.  
  62. #include "FastLED.h"
  63. #define LED_TYPE WS2812B
  64. #define DATA_PIN 13
  65. #define NUM_LEDS 51
  66. #define MASTER_BRIGHTNESS 255 // Set the master brigtness value [should be greater then min_brightness value].
  67. uint8_t min_brightness = 10; // Set a minimum brightness level.
  68. uint8_t brightness; // Mapped master brightness based on potentiometer reading.
  69. CRGB leds[NUM_LEDS];
  70.  
  71. int potPinA = A1; // Pin for potentiometer A (for hue)
  72. int potPinB = A0; // Pin for potentiometer B (for brightness)
  73. int potValA; // Variable to store potentiometer A value (for hue)
  74. int potValB; // Variable to store potentiometer B value (for brightness)
  75. uint8_t hue; // Hue color (0-255)
  76.  
  77.  
  78. //---------------------------------------------------------------
  79. void setup() {
  80. delay(500); // Power-up delay
  81. //Serial.begin(115200); // Allows serial monitor output (check baud rate)
  82. FastLED.addLeds<LED_TYPE,DATA_PIN>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  83. FastLED.setBrightness(MASTER_BRIGHTNESS); // Initially set the max brightness. Will continuously update it later.
  84. pinMode(potPinA, INPUT); // Set pin as an input.
  85. pinMode(potPinB, INPUT); // Set pin as an input.
  86. }
  87.  
  88.  
  89. //---------------------------------------------------------------
  90. void loop() {
  91. checkKnobs(); // Call function to check knob positions.
  92.  
  93. for (int i = 0; i < NUM_LEDS; i++) {
  94. leds[i] = CHSV(hue, 255, 255); // hue comes from pot A, and brightness value is scaled based on pot B.
  95. }
  96. FastLED.show();
  97. }
  98.  
  99.  
  100. //===============================================================
  101. void checkKnobs(){
  102. potValA = analogRead(potPinA); // Read potentiometer A (for hue).
  103. //potValA = map(potValA, 1023, 0, 0, 1023); // Reverse reading if potentiometer is wired backwards.
  104. hue = map(potValA, 0, 1023, 0, 255); // map(value, fromLow, fromHigh, toLow, toHigh)
  105.  
  106. potValB = analogRead(potPinB); // Read potentiometer B (for brightness).
  107. brightness = map(potValB, 0, 1023, min_brightness, MASTER_BRIGHTNESS);
  108. // Map value between min_brightness and MASTER brightness values.
  109. // Note: We are limiting the lowest possible brightness value to the
  110. // min_brightness value assigned up top.
  111. FastLED.setBrightness(brightness); // Set master brightness based on potentiometer position.
  112.  
  113. //Serial.print(" pot A: "); Serial.print(potValA); Serial.print(" hue: "); Serial.print(hue);
  114. //Serial.print(" pot B: "); Serial.print(potValB); Serial.print(" brightness: "); Serial.println(brightness);
  115. }
  116.  
  117.  
  118. //---------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement