Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. //FastLED_AnalougeInput.ino
  2.  
  3. #include <FastLED.h>
  4.  
  5.  
  6. #define LED_PIN 13 // which ping are LEDS connected to?
  7. #define NUM_LEDS 250
  8. #define COLOR_ORDER RGB
  9. #define LED_TYPE WS2811
  10. #define MAX_BRIGHTNESS 255 // watch the power!
  11.  
  12.  
  13. const int brightnessInPin = A0; // Analog input pin that the potentiometer is attached to
  14. const int speedInPin = A1; // Analog input pin that the potentiometer is attached to
  15.  
  16. struct CRGB leds[NUM_LEDS];
  17.  
  18. void setup() {
  19. delay(3000); // in case we do something stupid.
  20.  
  21. LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  22. FastLED.setBrightness(MAX_BRIGHTNESS);
  23. }
  24.  
  25. void loop() {
  26. // read the analog brightness value:
  27. int brightValue = analogRead(brightnessInPin);
  28. // map it to the range of the FastLED brightness:
  29. int outputValue = map(brightValue, 0, 1023, 0, 255);
  30. // now set the brightness of the strip
  31. FastLED.setBrightness(outputValue)
  32.  
  33. // read the analog speed value:
  34. int speedValue = analogRead(speedInPin);
  35. // map it to a value used in delay();
  36. int delayValue = map(speedValue, 0, 1023, 10, 300);
  37.  
  38.  
  39.  
  40. // First slide the led in one direction
  41. for(int i = 0; i < NUM_LEDS; i++) {
  42. // Set the i'th led to red
  43. leds[i] = CRGB::Red;
  44. // Show the leds
  45. FastLED.show();
  46. // now that we've shown the leds, reset the i'th led to black
  47. leds[i] = CRGB::Black;
  48. // Wait a little bit before we loop around and do it again
  49. delay(delayValue);
  50. }
  51.  
  52.  
  53. // Now go in the other direction.
  54. for(int i = NUM_LEDS-1; i >= 0; i--) {
  55. // Set the i'th led to red
  56. leds[i] = CRGB::Red;
  57. // Show the leds
  58. FastLED.show();
  59. // now that we've shown the leds, reset the i'th led to black
  60. leds[i] = CRGB::Black;
  61. // Wait a little bit before we loop around and do it again
  62. delay(delayValue);
  63. }
  64.  
  65.  
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement