hello! I am in need of help in making a neopixel strip do a strobe-like motion.
here is my code:
#include <Adafruit_NeoPixel.h>
#define PIN 2 // input pin Neopixel is attached to
#define NUMPIXELS 8 // number of neopixels in strip
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 100; // timing delay in milliseconds
int redColor = 255;
int greenColor = 165;
int blueColor = 0;
void setup() {
// Initialize the NeoPixel library.
pixels.begin();
}
void loop() {
setColor();
for (int i=0; i < NUMPIXELS; i++) {
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(redColor, greenColor, blueColor));
// This sends the updated pixel color to the hardware.
pixels.show();
// Delay for a period of time (in milliseconds).
delay(delayval);
}
}
void setColor(){
redColor = (255);
greenColor = (191);
blueColor = (0);
}
any help is always appreciated!
also here's a circuit image
by the way, this uses 8 pixels, as shown.
daxmangaming:
a strobe-like motion.
Say more . What does the code you have now do? What do you want it to do?
A strobe light is usually on and off at high speeds. Or flashing at a lower rate.
You seem to be aiming for some kind of animated effect; to suggest help on the programming would need a description of the desired behaviour.
a7
What do you need help with ?
blh64
January 8, 2025, 3:53pm
5
Your current code sets all the LEDs to a given color and then displays them. If you want them to strobe, then you will have to turn them all off (set them to black or 0,0,0) and display that and then repeat.
Have you given that a try?
I guess its supposed to be a police light animation, 4 LEDs are amber, and 4 are white.
and I want it to do exactly what a police light does.
DaveX
January 8, 2025, 7:39pm
8
Police lights do many things.
#include <Adafruit_NeoPixel.h>
#define PIN 2 // input pin Neopixel is attached to
#define NUMPIXELS 8 // number of neopixels in strip
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // timing delay in milliseconds
int redColor;
int greenColor;
int blueColor;
int idx;
void setup() {
// Initialize the NeoPixel library.
pixels.begin();
}
void loop()
{
setYel();
for (idx=0; idx < 4; idx++)
{
pixels.setPixelColor(idx, pixels.Color(redColor, greenColor, blueColor));
}
pixels.show();
setWht();
for (idx=4; idx < 8; idx++)
{
pixels.setPixelColor(idx, pixels.Color(redColor, greenColor, blueColor));
}
pixels.show();
delay(delayval);
setWht();
for (idx=0; idx < 4; idx++)
{
pixels.setPixelColor(dxi, pixels.Color(redColor, greenColor, blueColor));
}
pixels.show();
setYel();
for (idx=4; idx < 8; idx++)
{
pixels.setPixelColor(idx, pixels.Color(redColor, greenColor, blueColor));
}
pixels.show();
delay(delayval);
}
void setYel()
{
redColor = (255);
greenColor = (191);
blueColor = (0);
}
void setWht()
{
redColor = 240;
greenColor = 240;
blueColor = 240;
}
thank you I will test this code!
the code has errors, says tinkercad at least. the errors are that "i" isn't declared what it is.
I didn't use "i". I used "idx".
check your code again. it has i in it and it shows errors
Wow - such a critic.
I changed it, forgot a couple of i's. (Don't use single-letter variables!)
thank you, just making sure, sorry if I seem mad, just bad typing skills
Yes, easily fixed.
It was easier to run this than to read it to see what it does.
Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!
// wokwi.com/projects/419543065589286913
# include <Adafruit_NeoPixel.h>
# define PIN 2 // input pin Neopixel is attached to
# define NUMPIXELS 12 // number of neopixels in strip
# define HALFTHAT 6
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // timing delay in milliseconds
int redColor;
int greenColor;
int blueColor;
int idx;
void setup() {
// Initialize the NeoPixel library.
pixels.begin();
}
void loop()
{
setYel();
for (idx = 0; idx < HALFTHAT; idx++)
{
pixels.setPixelColor(idx, pixels.Color(redColor, greenColor, blueColor));
}
pixels.show();
setWht();
for (idx = HALFTHAT; idx < NUMPIXELS; idx++)
{
pixels.setPixelColor(idx, pixels.Color(redColor, greenColor, blueColor));
}
pixels.show();
delay(delayval);
setWht();
for (idx = 0; idx < HALFTHAT; idx++)
{
pixels.setPixelColor(idx, pixels.Color(redColor, greenColor, blueColor));
}
pixels.show();
setYel();
for (idx = HALFTHAT; idx < NUMPIXELS; idx++)
{
pixels.setPixelColor(idx, pixels.Color(redColor, greenColor, blueColor));
}
pixels.show();
delay(delayval);
}
void setYel()
{
redColor = (255);
greenColor = (191);
blueColor = (0);
}
void setWht()
{
redColor = 240;
greenColor = 240;
blueColor = 240;
}
HTH
a7
Now some bot's got in on the act.