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