Thursday, 2 July 2026

New LED box project

 22 ws2811 LEDs

1 Arduino Uno

connect green wire of LEDs to pin 5

connect red wire of LEDs to +5V

connect white wire of LEDs to GND


Connect USB cable to Arduino

Call up Arduino IDE software

select correct board (Tools/Board

select correct Port (COM 4 in my case)

verify and upload code:

all should work now

==================================================================

#include <FastLED.h>

#define LED_PIN      5
#define NUM_LEDS     22
#define LED_TYPE     WS2811
#define COLOR_ORDER  RGB
#define BRIGHTNESS   128

CRGB leds[NUM_LEDS];

const CRGB colours[] = {
  CRGB::Red,
  CRGB::Orange,
  CRGB::Yellow,
  CRGB::Green,
  CRGB::Cyan,
  CRGB::Blue,
  CRGB::Purple
};



const uint8_t NUM_COLOURS = sizeof(colours) / sizeof(colours[0]);
const unsigned long FADE_TIME = 5000; // 5 seconds

uint8_t currentColour = 0;
unsigned long fadeStart;

void setup() {
  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);

  fadeStart = millis();
}

void loop() {
  unsigned long elapsed = millis() - fadeStart;

  // Calculate fade progress (0-255)
  uint8_t blendAmount = (elapsed * 255UL) / FADE_TIME;

  if (elapsed >= FADE_TIME) {
    currentColour = (currentColour + 1) % NUM_COLOURS;
    fadeStart = millis();
    blendAmount = 0;
  }

  CRGB current = colours[currentColour];
  CRGB next = colours[(currentColour + 1) % NUM_COLOURS];

  CRGB blended = blend(current, next, blendAmount);

  fill_solid(leds, NUM_LEDS, blended);
  FastLED.show();

  FastLED.delay(20); // ~50 FPS
}

==================================================================


No comments:

Post a Comment