Advertisement
GyroGearloose

FastLED control analog LEDs

Feb 4th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. // Example showing how to use FastLED color functions
  4. // even when you're NOT using a "pixel-addressible" smart LED strip.
  5. //
  6. // This example is designed to control an "analog" RGB LED strip
  7. // (or a single RGB LED) being driven by Arduino PWM output pins.
  8. // So this code never calls FastLED.addLEDs() or FastLED.show().
  9. //
  10. // This example illustrates one way you can use just the portions
  11. // of FastLED that you need.  In this case, this code uses just the
  12. // fast HSV color conversion code.
  13. //
  14. // In this example, the RGB values are output on three separate
  15. // 'analog' PWM pins, one for red, one for green, and one for blue.
  16.  
  17. #define REDPIN   5
  18. #define GREENPIN 6
  19. #define BLUEPIN  3
  20.  
  21. // showAnalogRGB: this is like FastLED.show(), but outputs on
  22. // analog PWM output pins instead of sending data to an intelligent,
  23. // pixel-addressable LED strip.
  24. //
  25. // This function takes the incoming RGB values and outputs the values
  26. // on three analog PWM output pins to the r, g, and b values respectively.
  27. void showAnalogRGB( const CRGB& rgb)
  28. {
  29.   analogWrite(REDPIN,   rgb.r );
  30.   analogWrite(GREENPIN, rgb.g );
  31.   analogWrite(BLUEPIN,  rgb.b );
  32. }
  33.  
  34.  
  35.  
  36. // colorBars: flashes Red, then Green, then Blue, then Black.
  37. // Helpful for diagnosing if you've mis-wired which is which.
  38. void colorBars()
  39. {
  40.   showAnalogRGB( CRGB::Red );   delay(500);
  41.   showAnalogRGB( CRGB::Green ); delay(500);
  42.   showAnalogRGB( CRGB::Blue );  delay(500);
  43.   showAnalogRGB( CRGB::Black ); delay(500);
  44. }
  45.  
  46. void loop()
  47. {
  48.   static uint8_t hue;
  49.   hue = hue + 1;
  50.   // Use FastLED automatic HSV->RGB conversion
  51.   showAnalogRGB( CHSV( hue, 255, 255) );
  52.  
  53.   delay(20);
  54. }
  55.  
  56.  
  57. void setup() {
  58.   pinMode(REDPIN,   OUTPUT);
  59.   pinMode(GREENPIN, OUTPUT);
  60.   pinMode(BLUEPIN,  OUTPUT);
  61.  
  62.   // Flash the "hello" color sequence: R, G, B, black.
  63.   colorBars();
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement