#include <FastLED.h>
#define LED_DATA_PIN 12
#define NUM_LEDS 30
#define LEFT_LED_PIN 11 // Pin for left indicator LED
#define RIGHT_LED_PIN 10 // Pin for right indicator LED
#define LEFT_PIEZO_PIN 9 // Pin for left piezo buzzer
#define RIGHT_PIEZO_PIN 8 // Pin for right piezo buzzer
#define VOLUME_POT_PIN A3 // Analog input pin for volume potentiometer
#define LEFT_RIGHT_LED_BRIGHTNESS_PIN A2 // Analog input pin for left/right LED brightness potentiometer
#define STRIP_BRIGHTNESS_POT_PIN A4 // Analog input pin for LED strip brightness potentiometer
#define RED_POT_PIN A5 // Analog input pin for red color potentiometer
#define GREEN_POT_PIN A6 // Analog input pin for green color potentiometer
#define BLUE_POT_PIN A7 // Analog input pin for blue color potentiometer
CRGB leds[NUM_LEDS];
int potSpeed = A0; // Analog input pin for potentiometer
int potTone = A1; // Analog input pin for tone potentiometer
void playTone(int pin, int frequency, int volume) {
tone(pin, frequency, volume);
}
void setup() {
FastLED.addLeds<WS2812B, LED_DATA_PIN, GRB>(leds, NUM_LEDS);
pinMode(LEFT_LED_PIN, OUTPUT);
pinMode(RIGHT_LED_PIN, OUTPUT);
pinMode(LEFT_PIEZO_PIN, OUTPUT);
pinMode(RIGHT_PIEZO_PIN, OUTPUT);
}
void loop() {
int speed = map(analogRead(potSpeed), 0, 1023, 10, 50); // Map potentiometer to control speed
int toneFrequency = map(analogRead(potTone), 0, 1023, 50, 2000); // Map potentiometer to control piezo tone
int volume = map(analogRead(VOLUME_POT_PIN), 0, 1023, 0, 255); // Map potentiometer to control piezo volume
int stripBrightness = map(analogRead(STRIP_BRIGHTNESS_POT_PIN), 0, 1023, 0, 255); // Map potentiometer to control LED strip brightness
int leftRightLedBrightness = map(analogRead(LEFT_RIGHT_LED_BRIGHTNESS_PIN), 0, 1023, 0, 255); // Map potentiometer to control left/right LED brightness
int redValue = map(analogRead(RED_POT_PIN), 0, 1023, 0, 255); // Map potentiometer to control red component of color
int greenValue = map(analogRead(GREEN_POT_PIN), 0, 1023, 0, 255); // Map potentiometer to control green component of color
int blueValue = map(analogRead(BLUE_POT_PIN), 0, 1023, 0, 255); // Map potentiometer to control blue component of color
// Set brightness for LED strip
FastLED.setBrightness(stripBrightness);
// Set color for LED strip
CRGB color = CRGB(redValue, greenValue, blueValue);
// Move the color from left to right
for (int i = 0; i < NUM_LEDS; i++) {
// Turn on the current LED to the specified color
leds[i] = color;
// Show the LEDs
FastLED.show();
// Clear the current LED for the next iteration
leds[i] = CRGB::Black;
// Wait for a short duration to create the illusion of movement
delay(speed);
// Check if LED reaches the left side
if (i == 0 && i != NUM_LEDS - 1) {
digitalWrite(LEFT_LED_PIN, HIGH); // Turn on the left indicator LED
analogWrite(RIGHT_LED_PIN, leftRightLedBrightness); // Set brightness of right LED
playTone(LEFT_PIEZO_PIN, toneFrequency, volume); // Play tone on left piezo buzzer
} else {
digitalWrite(LEFT_LED_PIN, LOW); // Turn off the left indicator LED
noTone(LEFT_PIEZO_PIN); // Stop tone on left piezo buzzer
digitalWrite(RIGHT_LED_PIN, LOW); // Turn off the right indicator LED
}
}
// Move the color from right to left
for (int i = NUM_LEDS - 1; i >= 0; i--) {
// Turn on the current LED to the specified color
leds[i] = color;
// Show the LEDs
FastLED.show();
// Clear the current LED for the next iteration
leds[i] = CRGB::Black;
// Wait for a short duration to create the illusion of movement
delay(speed);
// Check if LED reaches the right side
if (i == NUM_LEDS - 1 && i != 0) {
digitalWrite(RIGHT_LED_PIN, HIGH); // Turn on the right indicator LED
analogWrite(LEFT_LED_PIN, leftRightLedBrightness); // Set brightness of left LED
playTone(RIGHT_PIEZO_PIN, toneFrequency, volume); // Play tone on right piezo buzzer
} else {
digitalWrite(RIGHT_LED_PIN, LOW); // Turn off the right indicator LED
noTone(RIGHT_PIEZO_PIN); // Stop tone on right piezo buzzer
digitalWrite(LEFT_LED_PIN, LOW); // Turn off the left indicator LED
}
}
}
Tone
Strip Red, Green, Blue
Strip brightness
Strip speed
Volume
Buzz
intensity