hi friends, I hope you'r well
In fact, I programmed a led rgb 2812 tape with arduino uno. The problem is that at the start of the program, the pixels light up in sequence, and this is quite visible with the eye.
This problem also exists when changing the color of the led, and the pixels execute the change again, one after the other.
What do I need to change to be able to turn on my LED strip pixels simultaneously and without interruption? Will this problem be solved? I am grateful for your guidance and I am grateful for your time to guide me...
that's my code:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define PIN 6
#define NUMPIXELS 240
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
void setup() {
pixels.begin();
}
void loop() {
pixels.clear();
pixels.setBrightness(10);
for( int i=0; i>20; i++){
pixels.setPixelColor(i, pixels.Color(255, 255, 255));
}
pixels.setPixelColor(1, pixels.Color(255, 0, 0));
pixels.setPixelColor(2, pixels.Color(0, 255, 0));
pixels.setPixelColor(3, pixels.Color(0, 0, 255));
pixels.setPixelColor(4, pixels.Color(255, 0, 255));
pixels.setPixelColor(5, pixels.Color(255, 255, 0));
pixels.setPixelColor(6, pixels.Color(0, 255, 255));
pixels.show();
}
Congratulations! There is million and one way of doing it, just in case you realise that it might help see the code
The code that you have not posted
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use [color = red]code tags [/color] (the </> icon above the compose window) to make it easier to read and copy for examination
See also FAQ - Arduino Forum for general rules on forum behavior and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is frus…
Your post was MOVED to its current location as it is more suitable
Cool, posted the code.
It looks like 20 led pixels will be set to white but not show white till a pixels.show is called.
Now that the 20 pixels have been set to all white, then there is this,
cnaroshan:
pixels.setPixelColor(1, pixels.Color(255, 0, 0));
pixels.setPixelColor(2, pixels.Color(0, 255, 0));
pixels.setPixelColor(3, pixels.Color(0, 0, 255));
pixels.setPixelColor(4, pixels.Color(255, 0, 255));
pixels.setPixelColor(5, pixels.Color(255, 255, 0));
pixels.setPixelColor(6, pixels.Color(0, 255, 255));
Where the first 6 pixels are sent a new set of display insturctions.
Then
cnaroshan:
pixels.show();
is executed, now the first 6 pixels show the new info but the next 14 pixels go all white.
Then repeat. The repeat is done very quickly.
In this case, you might add a delay(1000); after the pixels.show() for demo purposes.
Please ignore below.
So the first 20 pixels get skipped and next you set the colour of roughly 32000 pixels that you don't have.
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project.
To @cnaroshan , @Idahowalker and @sterretje . Nope. This cycle is NOT execute at all.
Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!
Did you try
for( int i=0; i>20; i++){
pixels.setPixelColor(i, pixels.Color(255, 255, 255));
}
pixels.show()?
delay(10000000000000000000);
or
for( int i=0; i>20; i++){
pixels.setPixelColor(i, pixels.Color(255, 255, 255));
pixels.show()?
delay(1000000000000000000000000000000000000);
}
flashko
January 1, 2022, 12:22pm
12
Yep. I tested this simple program.
void setup ()
{
Serial.begin ( 115200 );
Serial.println ("*");
for( int i=0; i>20; i++)
{
Serial.println ( i );
}
Serial.println ("o");
}
void loop ()
{
;
}
The result in wokwi simulator and real Arduino Nano and Wemos D1 mini is the same - the cycle is NOT execute.
Of course it is never executed. Look more carefully at the for statement, as has been pointed out the condition is always false.
C++ for loop (tutorialspoint.com)
Pay particular attention to:
Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and flow of control jumps to the next statement just after the for loop.
Paul_B
January 1, 2022, 1:23pm
15
This of course elegantly illustrates a common principle of programming (and of course, most other human enterprises), and why we are in such a mess with the software we use nowadays.
The original creator knows what he wanted the code to do and he wrote it to do just that. He looks at it and it clearly follows his intention. So he remains puzzled when it just does not do what he wrote it to do.
A second (or third) observer immediately sees the problem.
Yes, exactly what I said and can be seen in practice. There is a logical block diagram of your link and it looks very good there.
After you have fixed the for loop, post your updated code.
flashko:
for( int i=0; i>20; i++)
How will i increment if i will only increment if i is greater than 20 but initially a 0 is loaded int i?
How is this different for( int i=0; i<20; i++)?
Hello, @Idahowalker .
It seems to me that you are mistaken. I am not an OP. I just noticed a bug in the program, that Is all.
Have a good year!
Sorry, my error and I meant no offense.
Paul_B
January 1, 2022, 9:44pm
20
OP appears to be MIA so far!
flashko
January 1, 2022, 10:46pm
21
No problem. Everything is fine.
By the way, what does MIA mean? English is not my native language.