Detection of different types of numbers

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.

Sure looks like a homework assignment.

Yeah it's for the workshop

Start with a program to blink the LED the way you want. then add to that program, bit by bit, testing each step of the way.

Assuming that you are interested in solving the task (mostly) by your own, here are some hints

For Armstrong Numbers:

https://www.javatpoint.com/armstrong-number-in-c

For Fibonacci Numbers:

https://www.javatpoint.com/fibonacci-series-in-c

For Palindrome Numbers

https://www.javatpoint.com/palindrome-program-in-c

How to blink the internal or an external LED

https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink

Now you just have to find out how to combine these ... :innocent:

1 Like

Thank you I will check all the links

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...

Ok thanks, I will try.

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" .

Oh ok

Trick question. :expressionless:

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.