Hi, i have 4 arduino sketches using ws2812b led stip with 4 different white led effects. i would like to put all 4 sketches into one sketch and add a button so i can change between the 4 effects, i am a complete novice with arduino code so any help would be appreciated
thanks ic
type or paste code h#include <FastLED.h>
// --- Configuration ---
#define NUM_LEDS 10// Total number of LEDs in your strip
#define DATA_PIN 3 // The Arduino pin connected to the Data In line
#define LED_TYPE WS2812B // Adjust to your specific LED type
#define COLOR_ORDER GRB // Adjust to your specific color order (may be RGB or BGR)
#define BRIGHTNESS 64 // Adjust brightness (0-255)
#define GROUP_SIZE 2 // Number of LEDs in each group
#define FLASH_DELAY 200 // Delay in milliseconds for each flash (controls speed)
// ---------------------
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS)
.setCorrection( TypicalLEDStrip );
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear(); // Turn all LEDs off
FastLED.show(); // Update the strip
}
void loop() {
// Loop through the strip in groups of three
for (int i = 0; i < NUM_LEDS; i += GROUP_SIZE) {
// Turn on the current group (set color to white)
for (int j = 0; j < GROUP_SIZE; j++) {
if (i + j < NUM_LEDS) { // Ensure we don't go out of bounds
leds[i + j] = CRGB::White;
}
}
FastLED.show(); // Display the change
delay(FLASH_DELAY);
// Turn off the current group (set color to black)
for (int j = 0; j < GROUP_SIZE; j++) {
if (i + j < NUM_LEDS) {
leds[i + j] = CRGB::Black; // Black is off
}
}
FastLED.show();
// Shorter delay after turning off to make the flash more distinct before moving on
delay(FLASH_DELAY / 2);
}
}
#include <FastLED.h>
// Define the number of LEDs in your strip
#define NUM_LEDS 10
// Define the pin the data line is connected to
#define DATA_PIN 3
// Define the LED type and color order (most common is WS2812B, GRB)
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
// Define the brightness (0-255)
#define BRIGHTNESS 80
// Define the delay between steps in milliseconds
#define CHASE_DELAY 100
// Define the size of the chasing block
#define CHASER_SIZE 4
// Define the color as white (RGB values: 255, 255, 255)
#define CHASER_COLOR CRGB(255, 255, 255)
// Create an array of LEDs
CRGB leds[NUM_LEDS];
void setup() {
// Initialize FastLED
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear(); // Turn off all LEDs initially
FastLED.show();
}
void loop() {
// Loop through each LED position
for (int i = 0; i <= NUM_LEDS; i++) {
// Turn off all LEDs before lighting the next block
FastLED.clear();
// Turn on a block of 3 LEDs starting at the current position 'i'
for (int j = 0; j < CHASER_SIZE; j++) {
// Check if the LED index is within bounds of the strip
if (i + j < NUM_LEDS) {
leds[i + j] = CHASER_COLOR;
}
}
// Display the changes on the strip
FastLED.show();
// Wait before moving to the next position
delay(CHASE_DELAY);
}
}
#include "FastLED.h"
// How many LEDs in your strip?
#define NUM_LEDS 10
// On which pin to connect the data line?
#define DATA_PIN 3
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
// Initialize the FastLED library
// Change WS2812B to the correct chip if you are using a different one (e.g., NEOPIXEL, SK6812)
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
// Set global brightness (optional)
FastLED.setBrightness(50);
FastLED.clear(); // Turn all LEDs off initially
}
void loop() {
// Move a single white LED for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed = whiteLed + 1) {
for(int whiteLed = 0; whiteLed < NUM_LEDS; whiteLed++) {
// Turn the current LED on to white, then show the LEDs
leds[whiteLed] = CRGB::White;
FastLED.show();
// Wait a little bit to control speed (adjust delay time as needed)
delay(30);
// Turn the current LED back to black (off) for the next loop around
leds[whiteLed] = CRGB::Black;
}
}
#include <FastLED.h>
// --- Configuration ---
#define NUM_LEDS 10 // Number of LEDs in your strip
#define DATA_PIN 3 // Arduino pin connected to the Data line (e.g., D6)
#define BRIGHTNESS 100 // Adjust brightness (0-255)
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup() {
// Initialize FastLED library
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); // Adjust WS2812B/GRB if using a different chip/color order
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
}
void loop() {
// Run the time travel effect
timeTravelChaser();
}
void timeTravelChaser() {
int delayTime = 100; // Initial delay in milliseconds (slowest speed)
int minDelay = 10; // Minimum delay for flashing effect
int delayDecrement = 5; // How much to speed up each cycle
while (delayTime >= minDelay) {
// Chaser effect with a 2-LED white bar
for (int i = 0; i < NUM_LEDS + 1; i++) {
// Clear previous LEDs
FastLED.clear();
// Turn on 2 white LEDs
if (i < NUM_LEDS) {
leds[i] = CRGB::White;
}
if (i + 1 < NUM_LEDS) {
leds[i + 1] = CRGB::White;
}
FastLED.show();
delay(delayTime); // Use the variable delay
}
// Speed up for the next cycle
delayTime -= delayDecrement;
}
// Final rapid flashing/strobe effect
flashRapidly(50, 20); // Flash 50 times with a 20ms delay
// Reset for the next loop, if desired
FastLED.clear();
FastLED.show();
delay(1000); // Pause before restarting the effect
}
void flashRapidly(int count, int flashDelay) {
for (int i = 0; i < count; i++) {
fill_solid(leds, NUM_LEDS, CRGB::White); // All LEDs white
FastLED.show();
delay(flashDelay);
FastLED.clear(); // All LEDs off
FastLED.show();
delay(flashDelay);
}
}

