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