imported from "final" folder
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
/// @file AnalogOutput.ino
|
||||
/// @brief Demonstrates how to use FastLED color functions even without a "pixel-addressible" smart LED strip.
|
||||
/// @example AnalogOutput.ino
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <FastLED.h>
|
||||
#include "./compat.h"
|
||||
|
||||
|
||||
|
||||
// Example showing how to use FastLED color functions
|
||||
// even when you're NOT using a "pixel-addressible" smart LED strip.
|
||||
//
|
||||
// This example is designed to control an "analog" RGB LED strip
|
||||
// (or a single RGB LED) being driven by Arduino PWM output pins.
|
||||
// So this code never calls FastLED.addLEDs() or FastLED.show().
|
||||
//
|
||||
// This example illustrates one way you can use just the portions
|
||||
// of FastLED that you need. In this case, this code uses just the
|
||||
// fast HSV color conversion code.
|
||||
//
|
||||
// In this example, the RGB values are output on three separate
|
||||
// 'analog' PWM pins, one for red, one for green, and one for blue.
|
||||
|
||||
#define REDPIN 5
|
||||
#define GREENPIN 6
|
||||
#define BLUEPIN 3
|
||||
|
||||
// showAnalogRGB: this is like FastLED.show(), but outputs on
|
||||
// analog PWM output pins instead of sending data to an intelligent,
|
||||
// pixel-addressable LED strip.
|
||||
//
|
||||
// This function takes the incoming RGB values and outputs the values
|
||||
// on three analog PWM output pins to the r, g, and b values respectively.
|
||||
void showAnalogRGB( const CRGB& rgb)
|
||||
{
|
||||
analogWrite(REDPIN, rgb.r );
|
||||
analogWrite(GREENPIN, rgb.g );
|
||||
analogWrite(BLUEPIN, rgb.b );
|
||||
}
|
||||
|
||||
|
||||
|
||||
// colorBars: flashes Red, then Green, then Blue, then Black.
|
||||
// Helpful for diagnosing if you've mis-wired which is which.
|
||||
void colorBars()
|
||||
{
|
||||
showAnalogRGB( CRGB::Red ); delay(500);
|
||||
showAnalogRGB( CRGB::Green ); delay(500);
|
||||
showAnalogRGB( CRGB::Blue ); delay(500);
|
||||
showAnalogRGB( CRGB::Black ); delay(500);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static uint8_t hue;
|
||||
hue = hue + 1;
|
||||
// Use FastLED automatic HSV->RGB conversion
|
||||
showAnalogRGB( CHSV( hue, 255, 255) );
|
||||
|
||||
delay(20);
|
||||
}
|
||||
|
||||
|
||||
void setup() {
|
||||
pinMode(REDPIN, OUTPUT);
|
||||
pinMode(GREENPIN, OUTPUT);
|
||||
pinMode(BLUEPIN, OUTPUT);
|
||||
|
||||
// Flash the "hello" color sequence: R, G, B, black.
|
||||
colorBars();
|
||||
}
|
||||
42
.pio/libdeps/esp01_1m/FastLED/examples/AnalogOutput/compat.h
Normal file
42
.pio/libdeps/esp01_1m/FastLED/examples/AnalogOutput/compat.h
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
|
||||
#ifdef ARDUINO_ESP32_DEV
|
||||
#include "fl/compiler_control.h"
|
||||
|
||||
#include "platforms/esp/esp_version.h"
|
||||
#include "driver/ledc.h"
|
||||
#include "esp32-hal-ledc.h"
|
||||
|
||||
// Ancient versions of ESP32 on Arduino (IDF < 4.0) did not have analogWrite() defined.
|
||||
// IDF 4.4 and 5.0+ both have analogWrite() available, so this polyfill is only needed
|
||||
// for very old IDF versions. We use a weak symbol so it auto-disables on newer platforms.
|
||||
#if !ESP_IDF_VERSION_4_OR_HIGHER
|
||||
FL_LINK_WEAK void analogWrite(uint8_t pin, int value) {
|
||||
// Setup PWM channel for the pin if not already done
|
||||
static bool channels_setup[16] = {false}; // ESP32 has 16 PWM channels
|
||||
static uint8_t channel_counter = 0;
|
||||
|
||||
// Find or assign channel for this pin
|
||||
static uint8_t pin_to_channel[40] = {255}; // ESP32 has up to 40 GPIO pins, 255 = unassigned
|
||||
if (pin_to_channel[pin] == 255) {
|
||||
pin_to_channel[pin] = channel_counter++;
|
||||
if (channel_counter > 15) channel_counter = 0; // Wrap around
|
||||
}
|
||||
|
||||
uint8_t channel = pin_to_channel[pin];
|
||||
|
||||
// Setup channel if not already done
|
||||
if (!channels_setup[channel]) {
|
||||
ledcSetup(channel, 5000, 8); // 5kHz frequency, 8-bit resolution
|
||||
ledcAttachPin(pin, channel);
|
||||
channels_setup[channel] = true;
|
||||
}
|
||||
|
||||
// Write PWM value (0-255 for 8-bit resolution)
|
||||
ledcWrite(channel, value);
|
||||
}
|
||||
#endif // !ESP_IDF_VERSION_4_OR_HIGHER
|
||||
|
||||
|
||||
|
||||
#endif // ESP32
|
||||
Reference in New Issue
Block a user