Chasing Led
This is an Arduino project that drives a WS2812B Addressable LED panel with the push a the button. The lights cascades from clockwise to counter clockwise on the circle or snakes its way from one side to the other on the square. you can use a strip if you prefer
https://youtube.com/shorts/yc9sM284M7A?feature=share
Supplies
Addressable LED, this project is designed for 16 but can be added easily by changing the number values
One 240 Ohms resistor and heat shrink tubing
One or two three pin male to female cable/s
One three pin female to female cable
Two pushbutton Switches, I used a 8 button
One 3 pin connector
First cut and strip back the insulation on of the three pin wires that will be the data line on the female to female cable. Solder the resistor between the two wire segments. When cool use the heat shrink tubing with a heat source to reinforce the cable. My Arduino bord has ground 5V and Signal in a nice 3 rows. They are indicated by ground / black, red/ 5v and signal / yellow. You may but its is more likely will need to connect pin 9 and 240 Ohms resistor wire, ground and 5v with single wire cables individually.
Break off 3 pins from your strip if needed and solder so that the 5V pin is in the center if posable. This will prevent accidental shorting of your 5V to ground. Data line shorted to ground dose no harm.
Attach the ground pin to the ground with the other two pins connecting to pin 13 and 12 to the pushbutton switch ground and the two pins closest to the ground
// Copy the folowing code to a new Arduino Sketch
// video link https://youtube.com/shorts/yc9sM284M7A?feature=share
#include "FastLED.h" // This is the Fastled library to control the LEDs (installed it on your PC)
int x =0;
int y =0;
int z =0;
int caseVar = 0; // picks the case for switch command
char(colour);
// constants won't change. They're used here to set pin numbers:
const int buttonPin1 = 12; // the number of the pushbutton pin
const int buttonPin2 = 13; // the number of the pushbutton pin
#define NUM_LEDS 16 // defines led array
#define DATA_PIN 9 // defines data pin
CRGB leds[NUM_LEDS];
int ledNum = 0;
// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
void setup() {
delay(2000); // safety measure to help if Arduino brown outs
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS); // sets up FastLED function
Serial.begin(9600);
}
void loop() {
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
// buttonState3 = digitalRead(buttonPin3);
if (buttonState1 == HIGH){x=0;}else {x=1;}
if (buttonState2 == HIGH){y=0;}else {y=2;}
caseVar = x+y+z;
switch (caseVar) {
case 1:
//do something when var equals 1
ledChase();
break;
case 2:
//do something when var equals 2
ledChase1();
default:
// if nothing else matches, do the default
// default is optional
break;
}
// Serial.println(caseVar);
delay (50);
}
void ledChase(){
for( ledNum = 0; ledNum < NUM_LEDS; ledNum = ledNum + 1)
{
leds[ledNum] = CRGB::DimGray;
FastLED.show();
delay(50); // change to increes or decrease speed
leds[ledNum] = CRGB:: Black;
FastLED.show();
// leds[ledNum]=0;
}
}
void ledChase1(){
for( ledNum = 15; ledNum > -1; ledNum = ledNum - 1 )
{
leds[ledNum] = CRGB:: Red;
FastLED.show();
delay(50);
leds[ledNum] = CRGB:: Black;
FastLED.show();
// leds[ledNum]=15;
}
}
The list below is all the colors you can change the sketch to. Want a color instead of black just select the one you want and have fun
CRGB::AliceBlue CRGB::Amethyst CRGB::AntiqueWhite CRGB::Aqua CRGB::Aquamarine CRGB::Azure
CRGB::Beige CRGB::Bisque CRGB::Black CRGB::BlanchedAlmond CRGB::Blue CRGB::BlueViolet
CRGB::Brown CRGB::BurlyWood CRGB::CadetBlue CRGB::Chartreuse CRGB::Chocolate CRGB::Coral
CRGB::CornflowerBlue CRGB::Cornsilk CRGB::Crimson CRGB::Cyan CRGB::DarkBlue CRGB::DarkCyan
CRGB::DarkGoldenrod CRGB::DarkGray CRGB::DarkGreen CRGB::DarkKhaki CRGB::DarkMagenta
CRGB::DarkOliveGreen CRGB::DarkOrange CRGB::DarkOrchid CRGB::DarkRed CRGB::DarkSalmon
CRGB::DarkSeaGreen CRGB::DarkSlateBlue CRGB::DarkSlateGray CRGB::DarkTurquoise CRGB::DarkViolet
CRGB::DeepPink CRGB::DeepSkyBlue CRGB::DimGray CRGB::DodgerBlue CRGB::FireBrick CRGB::FloralWhite
CRGB::ForestGreen CRGB::Fuchsia CRGB::Gainsboro CRGB::GhostWhite CRGB::Gold CRGB::Goldenrod
CRGB::Gray CRGB::Green CRGB::GreenYellow CRGB::Honeydew CRGB::HotPink CRGB::IndianRed
CRGB::Indigo CRGB::Ivory CRGB::Khaki CRGB::Lavender CRGB::LavenderBlush CRGB::LawnGreen
CRGB::LemonChiffon CRGB::LightBlue CRGB::LightCoral CRGB::LightCyan CRGB::LightGoldenrodYellow
CRGB::LightGreen CRGB::LightGrey CRGB::LightPink CRGB::LightSalmon CRGB::LightSeaGreen
CRGB::LightSkyBlue CRGB::LightSlateGray CRGB::LightSteelBlue CRGB::LightYellow CRGB::Lime
CRGB::LimeGreen CRGB::Linen CRGB::Magenta CRGB::Maroon CRGB::MediumAquamarine
CRGB::MediumBlue CRGB::MediumOrchid CRGB::MediumPurple CRGB::MediumSeaGreen
CRGB::MediumSlateBlue CRGB::MediumSpringGreen CRGB::MediumTurquoise CRGB::MediumVioletRed
CRGB::MidnightBlue CRGB::MintCream CRGB::MistyRose CRGB::Moccasin CRGB::NavajoWhite
CRGB::Navy CRGB::OldLace CRGB::Olive CRGB::OliveDrab CRGB::Orange CRGB::OrangeRed
CRGB::Orchid CRGB::PaleGoldenrod CRGB::PaleGreen CRGB::PaleTurquoise CRGB::PaleVioletRed
CRGB::PapayaWhip CRGB::PeachPuff CRGB::Peru CRGB::Pink CRGB::Plaid CRGB::Plum
CRGB::PowderBlue CRGB::Purple CRGB::Red CRGB::RosyBrown CRGB::RoyalBlue CRGB::SaddleBrown
CRGB::Salmon CRGB::SandyBrown CRGB::SeaGreen CRGB::Seashell CRGB::Sienna CRGB::Silver
CRGB::SkyBlue CRGB::SlateBlue CRGB::SlateGray CRGB::Snow CRGB::SpringGreen CRGB::SteelBlue
CRGB::Tan CRGB::Teal CRGB::Thistle CRGB::Tomato CRGB::Turquoise CRGB::Violet CRGB::Wheat
CRGB::White CRGB::WhiteSmoke CRGB::Yellow CRGB::YellowGreen