I asked Shako.ai…
“You asked:
Arduino R3 multicolour LED strip controller program
Shako.ai replied
Here is an example of a program for controlling a multicolour LED strip using an Arduino R3 board:
C:
#include <Adafruit_NeoPixel.h>
2
3const int LED_PIN = 8; // Pin the LED strip is connected to
4const int NUM_LEDS = 8 * 64; // Number of LEDs in the strip
5const int STRIP_WS2812 = 5; // Pin the WS2812 chip is connected to
6
7Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
8
9void setup() {
10 strip.begin();
11 pinMode(LED_PIN, OUTPUT);
12}
13
14void loop() {
15 strip.setPixelColor(0, 0, 255, 0); // Set the first LED to red
16 strip.setPixelColor(1, 0, 0, 255); // Set the second LED to green
17 strip.setPixelColor(2, 0, 0, 0); // Set the third LED to blue
18 strip.show();
19 delay(1000);
20}
21
[mod edit: put the code in a code box for better readability]
This program uses the Adafruit NeoPixel library to control an 8x64 LED strip connected to the Arduino R3 board. The
`strip` object is initialized with the number of LEDs in the strip, the pin the LED strip is connected to, and the color order (GRB).
In the
`loop()` function, the first three LEDs are set to red, green, and blue, respectively, and the
`strip.show()` function is called to turn on all the LEDs. A delay of 1000 milliseconds is added to allow the colors to fade smoothly.
This is just a simple example, and the colors and timing can be adjusted to create different effects. It is also possible to use the
`strip.setPixelColor()` function to individually control the color of each LED in the strip.
It is important to note that the LED strip should be connected to a power supply that can provide enough current to drive all the LEDs, and to properly bias the LED strip to ensure stable operation.