/**
* @file B_Safe_Sinelon_Standby.ino
* @author B.Safe Security Systems (adapted by AI)
* @brief A standalone "Sinelon" (or "Cylon") light scanner effect.
*
* This sketch creates a colored dot that sweeps back and forth along the LED
* strip, leaving a fading trail behind it. The color of the dot slowly cycles
* through the rainbow.
*
* This is a simplified, standalone version intended for use as a default or
* standby pattern.
*/
#include <FastLED.h>
// --- Configuration: You can easily change these values ---
#define NUM_LEDS 60 // How many LEDs are in your strip?
#define LED_PIN 2 // The data pin your LED strip is connected to.
#define LED_TYPE WS2812B // The type of LED strip you are using.
#define COLOR_ORDER GRB // Color order of your LED strip. If colors are wrong, try RGB, GBR, etc.
#define BRIGHTNESS 150 // Set overall brightness (0-255). Start lower to be safe.
// --- Sinelon Effect Parameters ---
// How quickly the dot sweeps back and forth. Higher numbers are faster.
// Using two different speeds creates a more organic, weaving motion.
uint8_t sweepSpeed1 = 23;
uint8_t sweepSpeed2 = 28;
// How long the fading trail is. A lower number means a LONGER trail.
// (e.g., 20 = short trail, 2 = long trail).
uint8_t trailFadeRate = 8;
// Saturation and Brightness of the moving dot (0-255).
// 255 for saturation means the colors will be vibrant and pure.
uint8_t dotSaturation = 255;
uint8_t dotBrightness = 255;
// This variable will be used to slowly cycle through colors.
int hue = 0;
// This array holds the color data for each of the LEDs.
CRGB leds[NUM_LEDS];
// --- Main Program ---
void setup() {
// A small delay to allow power to stabilize.
delay(2000);
// Initialize the FastLED library.
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
// Set the global brightness scale.
FastLED.setBrightness(BRIGHTNESS);
// Clear all LEDs at startup.
FastLED.clear();
FastLED.show();
}
void loop() {
// Call the function that creates the Sinelon animation frame.
sinelon();
// Display the new frame on the LED strip.
FastLED.show();
// A small delay to control the frame rate. 16ms is about 60 frames per second.
FastLED.delay(16);
}
/**
* @brief Creates one frame of the Sinelon animation.
*
* This function fades all the pixels slightly to create the trail effect,
* then calculates the new position of the dot and lights it up with the
* current color.
*/
void sinelon() {
// 1. Fade all LEDs down by a small amount.
// This creates the fading trail effect. The 'trailFadeRate' variable
// controls how quickly the trail disappears.
fadeToBlackBy(leds, NUM_LEDS, trailFadeRate);
// 2. Calculate the dot's new position.
// 'beatsin16' creates a smooth sine wave that goes from 0 up to NUM_LEDS
// and back down. We use two sine waves at different speeds and average
// their positions to create a more complex, weaving motion.
int pos1 = beatsin16(sweepSpeed1, 0, NUM_LEDS - 1);
int pos2 = beatsin16(sweepSpeed2, 0, NUM_LEDS - 1);
int dotPosition = (pos1 + pos2) / 2;
// 3. Set the color of the dot at the new position.
// We use the += operator to add color, which makes the center of the
// dot brighter and blend nicely with the trail.
// CHSV() defines a color by its Hue, Saturation, and Value (Brightness).
// 'hue++ / 4' causes the hue to slowly shift over time, cycling through the rainbow.
leds[dotPosition] += CHSV(hue++ / 4, dotSaturation, dotBrightness);
}