Prompt Title: Arduino LED color changing.

Created 1 year ago
Votes 0
Views 293 times
0

Prompt Detail:

Sure, here's the modified code for controlling 6 different LED strips separately:

arduino
#include <FastLED.h> // Define the number of LED strips and LEDs per strip #define NUM_STRIPS 6 #define NUM_LEDS_PER_STRIP 6 // Define the pins used for each LED strip #define STRIP_1_PIN 2 #define STRIP_2_PIN 3 #define STRIP_3_PIN 4 #define STRIP_4_PIN 5 #define STRIP_5_PIN 6 #define STRIP_6_PIN 7 // Create an array of CRGB objects for each LED strip CRGB leds[NUM_STRIPS][NUM_LEDS_PER_STRIP]; void setup() { // Initialize each LED strip FastLED.addLeds<WS2812B, STRIP_1_PIN, GRB>(leds[0], NUM_LEDS_PER_STRIP); FastLED.addLeds<WS2812B, STRIP_2_PIN, GRB>(leds[1], NUM_LEDS_PER_STRIP); FastLED.addLeds<WS2812B, STRIP_3_PIN, GRB>(leds[2], NUM_LEDS_PER_STRIP); FastLED.addLeds<WS2812B, STRIP_4_PIN, GRB>(leds[3], NUM_LEDS_PER_STRIP); FastLED.addLeds<WS2812B, STRIP_5_PIN, GRB>(leds[4], NUM_LEDS_PER_STRIP); FastLED.addLeds<WS2812B, STRIP_6_PIN, GRB>(leds[5], NUM_LEDS_PER_STRIP); } void loop() { // Set the color of each LED in each strip for (int strip = 0; strip < NUM_STRIPS; strip++) { for (int led = 0; led < NUM_LEDS_PER_STRIP; led++) { // Calculate the color for this LED CRGB color; switch (led) { case 0: color = CRGB::Red; break; case 1: color = CRGB::Green; break; case 2: color = CRGB::Yellow; break; case 3: color = CRGB::Magenta; break; case 4: color = CRGB::Blue; break; case 5: color = CRGB::Aqua; break; } // Set the color for this LED in this strip leds[strip][led] = color; } } // Show the new LED colors for each strip for (int strip = 0; strip < NUM_STRIPS; strip++) { FastLED.show(leds[strip], NUM_LEDS_PER_STRIP); } // Wait for 1 minute delay(60000); }

In this modified code, we first define the number of LED strips and LEDs per strip. We then define the pins used for each LED strip, and create an array of CRGB objects for each strip.

In the setup function, we initialize each LED strip using the FastLED.addLeds function.

In the loop function, we set the color of each LED in each strip using a nested for loop. We use a switch statement to calculate the color for each LED based on its position in the strip. We then set the color of each LED in each strip using the leds array.

After setting the color of all the LEDs, we use another for loop to show the new LED colors for each strip

avatar
Dmytro
Shared 1 prompt
Created 1 year ago

Leave a Comment

Related Tag Prompts

0
0
製作LED閃爍裝置
1 year ago 2023-04-14 01:48:49 LED閃爍
0
0
Arduino Harry Potter Buzzer.
1 year ago 2023-04-22 01:04:10 James Slater
0
0
Arduino IoT API Hook.
1 year ago 2023-04-24 20:53:22 Dariusz