Exiting a function on a key press.

Paul,

Thanks for the info. I am not a full time programmer and so don't know the rules.

What I did do was make a basic flow chart and work from there.

The "display time" part was duplicated a few times and so I made that into it's own little block of code.
As with key scan.

I put them in UPPER CASE only because they were the names of the "functions" (or blocks of code) and for my benefit I put their names how I did.

Yeah, maybe not a good move for me if I want to become "one of the boys" at the IT department or write code for a job.

It isn't going to happen. I'm too old and many MANY other things.

I have read a few of the "standards" on how naming works, but it is ..... confusing to me. And honestly: Does it really matter?
So long as the code works and is understandable - isn't that the important part?

Some people put the { at the end of the line and the } on a line by itself.
I find it hard to read as I can't see the { and } easily - except for the indents - but I have to "read around" that problem.
It is pointless me complaining.

I would like to know how you would make a "function" for the DISPLAY_TIME so the two blocks of code can be reduced.
I am wort of working on it, but it is early days.

In another piece of code I worked out how to use .[ ] at the end to make arrays and saved 600 bytes of code.
I was very pleased with my self for that. It took a lot of work and effort.

The KEY_SCAN part:
Yeah, that is not nice.
Originally it was going to return simple values - like: 1, 2 , 3, 11, 12, 13 but I started to notice that in a couple of calls to it, I was adding 1, 10, or subtracting 1 or 10.

The code to get the key value and then act on it was long.

if (key_value == 1)
{

}
if (key_value == 10)
{

}

and so on.

As that was pretty well already done when the keys were scanned I decided to return the +1, +10, -1, -10 values.
I kept the global "key_value" just in case I did need it in future routines.

The code isn't finished.

I have since changed bits of the code and written more, but still not complete.
What I am doing is keeping the parts of code in different tabs as much as possible to help break it down.
Whether this is a good thing or not I am not sure, but for now it does help me with things, so I shall keep doing it.

Hope to hear back with more helpful suggestions. (Like the DISPLAY_TIME part.) Though I am looking at/working on it myself also.

This is a cut from the first part of what I have done to change it:

  if (gt == 0)
  {
    digitalWrite(D1_Select,HIGH);
  }
  if (gt == 1)
  {
    digitalWrite(D2_Select,HIGH);
  }
  if (digit == 0)
  {
    digitalWrite(Di1,LOW);
    digitalWrite(Di2,LOW);
    digitalWrite(Di3,LOW);
    digitalWrite(Di4,LOW);
  }

And so have basically halved the size of that part of the code.

Is that sort of what you were meaning?