question:
Initialize a counter and blink the onboard LED if the counter value is a Fibonacci number.
Connect another LED, let's say blue, and blink it if the counter value is a Palindrome. If the
counter value is an Armstrong number, reset to 0. Display all details on the serial monitor.
I am a newbie to Arduino programming so can anyone explain how to solve this problem? , I need the logic for solving this problem, code and different parameters needed to be considered.
Will still be some work ... Depending on how your coding skills are. @Paul_KD7HB already mentioned a reasonable way to progress: Start with a program to blink the LEDs and solve each further task step by step.
A good idea also is to make a short concept of the sketch with each task having names (even if those tasks are empty at the beginning). This way you can avoid to develop a "dead end street". Something like this is already a good start:
// Definitions and Declarations
unsigned long Counter;
// Setup = What to do once when the sketch starts
void setup{
Serial. begin(115200);
// E.g.: Set Counter to zero
Counter = 0;
Serial.println("Start of Counting");
}
void loop(){
Count();
if (CounterIsFibo()) BlinkLED1();
if (CounterIsPalindrom()) BlinkLED2();
// ...
}
void Count(){ Counter++};
boolean CounterIsFibo(){ };
boolean CounterIsPalindrom(){ };
void BlinkLED1(){ };
void BlinkLED2(){ };
and so on. And make use of Serial to print data to the Serial Monitor so that you can check, what is going on...
Good luck and feel free to ask when you got stuck. In that case please publish the code you are struggling with... But use the formatting for code, makes reading and copying easier for supporters.
One thing you could try to clarify is what behavior is expected from the sketch: Keep in mind that an Arduino is much quicker than humans in counting and checking the data. So how quick (or better slow) shall and must it be so that one can see the LEDs blinking? Shall it count with maximum speed or slower? To see the blinking you must at least wait for some time (maybe half a second or one second?)
Or shall the sketch stop counting when one of the checks was positive and wait for a command to go on?
So one thing is the algorithmic and the other the "man-machine-interface" .