PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AnalogOutput.ino 1.8KB

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