Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

Creating Stunning LED Animations with FastLED on Arduino

FastLED is a powerful library for programming addressable LEDs, such as WS2812B and APA102, with Arduino. It provides a high-level interface for controlling LED colors and animations, making it easier to create visually appealing projects. This article will guide you through setting up FastLED, understanding its features, and implementing a simple LED animation project. By the end of this article, you'll have a solid understanding of how to use FastLED to create stunning LED displays.

Project: In this project, we will create a simple LED animation using the FastLED library. Our objective is to control a strip of WS2812B LEDs connected to an Arduino and create a smooth color-changing effect. This project will demonstrate the basics of initializing the FastLED library, setting up the LED strip, and creating an animation loop.

Components List:

  1. Arduino Uno or compatible board (1)
  2. WS2812B LED strip (1 meter, 30 LEDs)
  3. 5V power supply (1)
  4. 470-ohm resistor (1)
  5. Capacitor (1000µF, 6.3V or higher) (1)
  6. Breadboard and jumper wires (as needed)

Examples:

#include <FastLED.h>  // Include the FastLED library

#define LED_PIN     6  // Define the pin where the LED strip is connected
#define NUM_LEDS    30 // Define the number of LEDs in the strip
#define BRIGHTNESS  64 // Set the brightness level (0-255)
#define LED_TYPE    WS2812B // Define the type of LED strip
#define COLOR_ORDER GRB // Define the color order (depends on the LED strip)

CRGB leds[NUM_LEDS]; // Create an array to hold the LED data

void setup() {
  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); // Initialize the LED strip
  FastLED.setBrightness(BRIGHTNESS); // Set the brightness
}

void loop() {
  static uint8_t hue = 0; // Create a static variable to hold the hue value
  for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = CHSV(hue++, 255, 255); // Set each LED to a color based on the hue value
  }
  FastLED.show(); // Update the LED strip with the new colors
  delay(20); // Add a small delay to create a smooth animation
}

Code Explanation:

  • #include <FastLED.h>: Includes the FastLED library.
  • #define LED_PIN 6: Defines the pin number to which the LED strip is connected.
  • #define NUM_LEDS 30: Defines the number of LEDs in the strip.
  • #define BRIGHTNESS 64: Sets the brightness level of the LEDs.
  • #define LED_TYPE WS2812B: Specifies the type of LED strip being used.
  • #define COLOR_ORDER GRB: Specifies the color order for the LED strip.
  • CRGB leds[NUM_LEDS]: Creates an array to store the color data for each LED.
  • void setup(): Initializes the LED strip and sets the brightness.
  • void loop(): Contains the main animation loop. It updates the color of each LED based on the hue value, increments the hue, and then updates the LED strip.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.