Hi. I have a question about a code from "Sparkfun Inverder's Kit."
In "Experiment 3: Driving an RGB LED," I have a problem to understand some of the codes. (Please look at the link below to see the sketch and hookup diagram.)
https://learn.sparkfun.com/tutorials/sik-experiment-guide-for-arduino---v32/experiment-3-driving-an-rgb-led
The first thing I would like you to explain is "int DISPLAY_TIME = 100;" I don't understand why this code is written in the sketch, because I don't find "DISPLAY_TIME" is used anywhere.
The next thing is that I don't understand what the following code means.
void loop(){
mainColors();
showSpectrum();
}
Why are there two commands in the loop command and how does this code work in the entire program?
Thanks!
It looks like the declaration of the DISPLAY_TIME variable was left in the code by mistake as it is not used. Naming constants is a good idea because it avoids "magic" numbers in programs such as in the 768 in
for (x = 0; x < 768; x++)If a well named constant, perhaps TOTAL_NUMBER_OF_COLOURS, had been used instead then the code would be easier to understand and if the number appears more than once in the code only the declaration of the variable needs to be altered if the number has to be changed.
void loop(){ //start of the loop() function
mainColors(); //call the mainColors() function. At the end of the function the program will continue at the next statement
showSpectrum(); //call the showSpectrum() function. At the end of the function the program will continue at the next statement
} //end of loop(). Now do the same things again