I have a question but never introduced myself.
I discovered the Arduino platform 1,5 years ago and was amazed... I gave up on electronics 30 years ago because I was ill but at 49 years old, I was better al last and able to enjoy all over again my electronics hobby but now with use of the Arduino!
After being bored looking at the blinking LED for 5 minutes, I decided to do something useful with the Arduino.
The DCF77 radio clocks are my sort of 'addiction', I love them and wanted to build one myself. But not the usual clocks but one that is able to display every bit received besides displaying the time etc.
It was a very steep learning curve, it was difficult but I enjoy my clock now every day.
But programming the clock was not very elegant to say it mildly. Experienced programmers will be laughing, rolling on the floor, seeing my code but it does work. ![]()
Someone mentioned a Finite State Machine but for me it was so overwhelming at that time!
Months later, I decided to make a very simple 'bedside' clock, with 3 buttons to set the time...
Simple? I immediately stumbled in the difficulty how on earth to program button input...
That's when I stumbled again into the Finite State Machine. This was my solution but how???
For newbies there is NO GOOD INFORMATION available on the whole internet... AMAZING
So after day of searching, I found this sketch.
In the comments, the author encouraged people to look through it and this way learn how Finite State Machine coding works. So I did and I was VERY ENTHUSIASTC, discovering the possibilities and getting structure im my programming which is hard enough for an inexperienced elderly man like me ![]()
QUESTION:
I used in my first attempt, separate functions for USERINPUT and TRANSITION, is this the right approach?
my loop() looks like this:
Full code here
Video (sorry, in Dutch...)
void loop()
{
executeState(); // execute (new) state of FSM
checkUserInput(); // check for button state/user input
checkRTCstatus(); // check connection with RTC, ERROR: activate decimal point
adjustBrightness(); // check ambient light and adjust the display brightness
}
I want to learn using Finite State Machine the right way from the start so comments are appreciated!