Setting RTC via remote keypad

UKHeliBob:
...you want them to enter it on some kind of remote device....Do you want each part of the date/time in separate variables...

Bob, correct in all areas. The method I control the scoreboard is with an remote I've made using an Arduino Mini Pro and nRF24L01 and keypad. I've programmed that the # key held down for 2 seconds sends the character "S" (ascii 83) to the control board. I'm planning on this initiating the date-time setting routine.

At this stage I'm just trying to work out how to capture each date number as a separate variables. Only once I've done that I thought I'd tackle the next part - to upload it to the RTC.

By the way, the one thing I would like to do is that when ascii 83 is received, the 4 digits that display the current time on the scoreboard change to 2000 (year 2000 as initial default). The "2" is preset and the 2nd character ("0") flashing waiting for keypad entry. When entered, the 3rd flashes, etc, etc. When the year is totally entered (2017), then the digits go to 0000 waiting for the MMDD. Same for HHMM. Seconds (00) will just automatically be set.

Any hint on how to start this would be appreciated.

How often do you need to set the time? The DS3231 is allegedly pretty accurate and I expect it's battery backed too, so it seems like it ought to be a rare occurrence. The interface through the remote doesn't seem very user friendly - I'd be inclined to get the time by other means - wifi or gps.

UKHeliBob:
As to how switch/case works it simply acts like a series of if/else if statements

Only if you remember the 'break' statements. Otherwise, the cases fall through -- which is sometimes what you want.

wildbill:
How often do you need to set the time? The DS3231 is allegedly pretty accurate and I expect it's battery backed too, so it seems like it ought to be a rare occurrence.

I'm just trying to look ahead in case I'm not available for the club to work on this scoreboard. I'm currently the only one in the club with a laptop loaded with the software and knowledge on how to change the time. I've left notes for others on how to do it, but that still would be difficult for someone.

If the date can be updated without a laptop and with equipment already there (remote), it's worth the effort.
When the RTC battery goes flat, the date will need to be updated.

I'm just trying to look ahead in case I'm not available for the club to work on this scoreboard.

Why does a scoreboard need to show the date and time?

PaulS:
Why does a scoreboard need to show the date and time?

You've never been to a test cricket match, I take it?

PaulS:
Why does a scoreboard need to show the date and time?

The date isn't displayed on the scoreboard. It's stored in the RTC.

This RTC displays the current "time" on the board so the players and ref can see the current time at a glance.
I'm also using the programmed date to adjust the time for day light savings in Melbourne.

A program to set the time is a really basic (textbook case) entry level programming problem. Stop begging and go and code it.

aarg:
A program to set the time is a really basic (textbook case) entry level programming problem. Stop begging and go and code it.

Aarg, my background is architecture, not programming. When I was at Uni 30 years ago all I learnt in regards to programming was simple addition in fortran via an antiquated card system!

As I said earlier in this thread, I spent over a year creating 1500 lines of code. I'm not simply being lazy.

I can easily write code and upload to an arduino via a laptop to run a clock and also update the time. Yes, entry level programming. However to send the signal remotely, write the code in the least possible lines, with efficiency and then upload it to an RTC via the library linked to my code may be entry level for you, but not me.

For me this is self tuition and a hobby. Hence the reason I'm asking for help on this forum. As I said earlier, I can start to write this a switch statement containing 120 case statement and I'm sure I could get it to work, but it would be nice to get a heads up on an approach on how to do it better.

You are no different than every other beginner. It is not feasible to offer general help with design approach and style in a forum setting. That is because of the volume of information. It is only possible to help with specific aspects, and it is not possible to identify areas of improvement that an individual needs without them first making an attempt at coding. There are a lot of suggestions on design and project management in the sticky posts at the top of the forum. There are numerous other resources on the internet that coach on coding, and to reproduce all that information in a thread is impossible. To reproduce significant parts of it is tedious, which is why it has been put in one place and made a sticky thread.

In spite of that limitation, a lot of design advice is handed out daily to many posters in this forum for specific issues and projects. If you also pay attention to those, you can glean quite a lot of wisdom.

However to send the signal remotely, write the code in the least possible lines, with efficiency and then upload it to an RTC via the library linked to my code may be entry level for you, but not me.

I've lost track of what you are trying to do. Post the code from before you tried to implement this latest feature (fiasco). Try to describe what the code should do, NOT how you think it should do it. Phrase your response like you were trying to hire a programmer.

At that point, we can understand what you are trying to accomplish. Then, we can make reasonable suggestions on how you might restructure your code to make the job easier to start.

Once you've done that, we can help you add the desired functionality.

aarg:
In spite of that limitation, a lot of design advice is handed out daily to many posters in this forum for specific issues and projects. If you also pay attention to those, you can glean quite a lot of wisdom.

Fair call. Sorry for the hassle.

The simplest time set is a left-right-up-down scheme. Up-down changes a digit value. Left-right cycles through the digits, reaching the endpoints is a set op.

cjcj:
Where I did get help however was in the "case" syntax. I don't really understand the rules about it.

For me, the key to understanding switch/case statements is understanding how the compiler compiles them. A switch statement usually gets turned into a computed GOTO statement in assembler. The compiler builds a jump table, and then computes an offset into that table from the value that you are switching on.

This

switch(a) {
case 1:
  some code;
  break;

case 2:
  some code;
  some code;

case 3:
  some code;
  break;
  
}

Usually (usually …) gets turned into something like this:

load a
jump relative a*2 ; assuming that a jump instruction is two bytes long
jump to case 1
jump to case 2
jump to case 3
; case 1
some code;
jump to end
; case 2
some code;
some code;
; case 3
some code;
jump to end
; end

you can see that having case labels that are variables makes no sense - that's simply not how it works. That case labels become jump commands in the generated code.

DS323x on battery lasts a looong time.
But you could put a cellular shield in the mix (after you fix everything else), and extract the time from their network. (AT+CCLK)
Cheap, accurate and DST aware.
All you need is cell. overage.

PaulS:
I've lost track of what you are trying to do. Post the code from before you tried to implement this latest feature (fiasco). Try to describe what the code should do, NOT how you think it should do it. Phrase your response like you were trying to hire a programmer.

Thanks Paul and sorry for the lack of clarity here. Attached is a copy of the functioning code (both for the remote transmitter and the receiver board) before my changes.

Currently to set the time, I connect my laptop via cable to the control board, open the sketch and via the serial monitor send through the UTC time in the format yyyy,mm,dd,hh,mm,ss. This uploads to the DS3231 attached to the board and the current AEST time display on 4 of the digits on the scoreboard.

What I would prefer to do so that "anyone" can re-adjust the time in future when the RTC battery goes flat, is to upload this time via the remote that runs the scoreboard. I'd also like for them to only have to upload the current AEST instead so as to not confuse them - the code can add the 10 hours for them.

I have 15 digits across the board - 3 for temperature, 4 for current time, 4 for timer, 2 for home score and 2 for visitors score. I'd like for the # key held down for 2 seconds to trigger a "change date-time" function and display this incrementally on the "time" digits, starting with year, then month+date, then hour+day.

As the program is executed and the user presses each number, the corresponding digit on the scoreboard is to flash from "0" to "nothing" to indicate which number they're on. Then when the button is pressed for that number, it displays on the board without flashing and goes to the next digit. As the year for example is finished to be typed, the digits then display 0000 and the first "0" flashes waiting for the month+date to be pressed. At the end, the string gets uploaded (once all numbers are keyed in).

Alternatively, aarg's suggestion of left right adjustment could also be a good idea. Maybe the current year displays on the current 4 "timer" digits, the month displays on the current "home score digits", the day displays on the current "away score digits" and the time displays in the usual "time" digits. Then the keypad 4 and 6 buttons (left and right) allows the user to move to the correct digit and the 2 and 8 buttons (up and down) allow the user to increment each number up and down as required. I think this would be better, but just sounds alot harder to do.

PaulMurray - the more I've been reading online, the more I've seen that the cases numbers can't take on a number via a loop variable - they need to be set up front. Your explanation of how it works makes more sense now.

lastchancename - your suggestion is probably the best (maintenance free), however not having dealt with that type of setup before (as a novice), it adds yet another level of complexity for me. Sorry.

_Controlboard_scoreboard1_06.ino (49.3 KB)

_Remote_scoreboard1_03.ino (22.7 KB)

Please hold any replies on this thread. I'm trying a plan "b".

2 second press of # on the remote initiates date-time editing. Xmas day 1pm gets displayed on the digits on the scoreboard 25 12 2017 13:00. The "0" in the year flashes. Keypress "2" and "8" increment this digit value up or down. Keypress "4" and "6" moves to the next digit or previous. Keypress # on the remote then completes the command and uploads the values (which were stored in variables during the setting). This means possibly 6 case switches rather than the 120 I originally though. I'll create this one step at a time and test as I go along.

Is this a good way of tackling this?

Is this a good way of tackling this?

6 switch cases sounds better than the 120 that you did not need in the first place but why do you even need 6 ?

At any time whilst adjusting the date/time you are waiting for 1 of 5 things to happen ie save/exit, increment current digit, decrement current digit, move to next digit or move to previous digit. One switch case.

It sounds like you still do not understand switch/case.

UKHeliBob:
6 switch cases sounds better than the 120 that you did not need in the first place but why do you even need 6 ?

Bob, I may be using the incorrect terminology. What I meant was I think I need 1 switch with 6 cases??? (case 67, case 69, case 71, case 73 and case 70 ). Holding the # key on the remote sends an "S" (ascii 83). Pressing a 2, 4, 6, 8 or 5 sends the ascii of C, E, G, T or F (67, 69, 71, 73 or 70). Does that make more sense?

So far I have the display going to 25 12 2017 1300 with holding down the # key.

case 67, case 69, case 71, case 73 and case 70

That's 5 cases, not 6, but the principle sounds OK

I suggest that instead of using numbers you use the characters sent. That will make the code easier to read and understand.