Creating a Table for logic decisions

I am brand new to Arduino and C++. (Fyi I have a C++ book on it's way from Amazon soon)

I want to create a table type record (QtrMinutes) to access each element individually (either down the line (e=e+1), or, dynamically e= 9 which would result in a "2" result), and make program logic decisions based on each individual element result.

Example:

QtrMinutes = 1,2,3,2,1,1,1,3,2,1,2,1,3,2,1,1,3,1,3,1,1,2,1,3,2,2,1,3,1,1,1,1,3,1,1,3,2,1,1,1,3,2,1,2,3,1,2,1,1,3,2,2,3,2,1,3,2,2,2,3,1,2,2,1,3,2,2,1,2,3,1,2,1,3,1,1,1,3,2,3,1,1,2,3,1,1,1,2,3,1,2,2,3,2,1,1,2,3,2,1,2,2,3,2,2,1,1,9;

Few Questions:

Do I use an Arduino/C++ Array, Record, Table, etc.?

Format?

Do I have to declare QtrMinutes in the "void setup (){...};" section as an integer, and/or length of the record's numeric string?

Is there a specific Command to access each element individually within the record (vs getting the whole string as one unit)?

No, you don’t want to declare it in setup, unless setup is the only place you refer to it.

Most of the rest I didn’t understand.

or, dynamically e= 9 which would result in a “2” result

QtrMinutes[9] is a 1, by my reckoning.

Do I have to declare QtrMinutes in the "void setup (){...};

You declare it at the top, before setup.

As for the rest, sorry, I'm with AWOL, not a clue what you mean.

I found this C Tutorial very useful when I first learnt C (I also found it useful having 2 friends to teach me...)

I suspect what you need is a global array variable.

What is the purpose of this array? That is, what's supposed to happen when one element gets chosen?

See XY problem.

Sounds like an array to me

Try this

byte anArray[] = {1, 2, 3, 2, 1, 1, 1, 3, 2, 1, 2, 1, 3, 2, 1, 1, 3, 1, 3, 1, 1, 2, 1, 3, 2, 2, 1, 3, 1, 1, 1, 1, 3, 1, 1, 3, 2, 1, 1, 1, 3, 2, 1, 2, 3, 1, 2, 1, 1, 3, 2, 2, 3, 2, 1, 3, 2, 2, 2, 3, 1, 2, 2, 1, 3, 2, 2, 1, 2, 3, 1, 2, 1, 3, 1, 1, 1, 3, 2, 3, 1, 1, 2, 3, 1, 1, 1, 2, 3, 1, 2, 2, 3, 2, 1, 1, 2, 3, 2, 1, 2, 2, 3, 2, 2, 1, 1, 9};
const byte NUMBER_OF_ELEMENTS =  sizeof(anArray) / sizeof(anArray[0]);

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  for (int x = 0; x < NUMBER_OF_ELEMENTS; x++)
  {
    Serial.print("element : ");
    Serial.print(x);
    Serial.print("\t"); //tab
    Serial.print(anArray[x]);
    if (anArray[x] == 3)
    {
      Serial.print("\tfound a 3");
    }
    Serial.println();
  }
}
void loop()
{
}

As far as the 9 for the element counting = "2", I was assuming to start with numbering 1-N... maybe I should start with numbering 0-N, then indeed the e=9 would result in "1". Thanks for the heads up!

Below is my pseudo-code, with the assumed logic I am hoping to program using Arduino/C++ commands and format.

I want to have a "record" that has a morse code "message" embedded, lighting an LED (later adding a 5v to 12v Relay to light many LEDs) in a light house structure.

The table record will be used to turn on and off individual "Dits" and "Dahs" for an alphabet (a-z) and a complete sentence, ased on the 1/4 hour and on the hour... during the rest of the time, the lighthouse LED(s) will just blink at a standard interval.

I may find in discovery that C++ has a better solution. But my Pseudo-code is my starting place.

But, I would like to use the multi-elements record solution now and in future applications, so I still need to understand how it would work in C++.

--- MY PSEUDO CODE---

My Arduino "Blinking Lighthouse" Programming Logic Psuedo-Code Overview (Draft 1)
(Updated: 31Dec2019 10:45PM California Time. rph)

DATABASE1 LAYOUT (Morse Code Light Sequencing)

Record1 Columns (Fields, "AthruZ") Data input

(Mulitple Morse Code Columns are used for each Character. The DB1 Record1 will contain "A,B,C,D,E...Z", which the Columns would be entered as
"12321113212132111313 ... 22119")

Record2 Columns (Fields, "Greetings Message") Data input

(Mulitple Morse Code Columns are used for each Character. The DB1 Record2 may contain "Greetings from Discovery Bay", which the Columns would be entered as
"2213121313132311321322131114112131213222322421131131113212132223111231312132122342111312321229")

Records Column Data Legend:

1 = DIT (10 ms Lamp On)

2 = DASH (30 ms Lamp On)

3 = INTER-CHARACTER (30 ms Lamp Off)

4 = INTER-WORD (70 ms Lamp Off)

9 = End Column(N) = Goto CLOCK-ROUTINE (End of data in Column, Start Over!)

Empty,0,6-8 = Error Routine

//RUN//:


CHECK-CLOCK (Realtime Clock)

If on the 1/4 hours time, Set CLOCK-CHECK-FLAG:
1=1/4 past hour
2=1/2 past hour
3=3/4 past hour
4=Top of the hour,
Otherwise = 0 (In-between)

HOUR-INTERRUPT-CHECK

If CLOCK-CHECK-FLAG =
0, CALL REVOLVING_LIGHTS-ROUTINE
1, 2, 3, CALL ABC-SERIES-LIGHTS-ROUTINE
4, CALL GREETING-MESSAGE-ROUTINE
5-9, Set ERROR-TYPE = 1, Goto ERROR-LAMP-ROUTINE


REVOLVING_LIGHTS-ROUTINE:

If CLOCK-CHECK = 0, Drive ROTATING-LIGHTS-SEQUENCE1
(Lamp Light is set Continously-ON, with Resistor-Capacitor-circuitry to allow timing of "Bright to Fadding to Bright..." sequencing)


ERROR-LAMP-ROUTINE (Lamp Dits On; Max times value):

If ERROR-TYPE = 1, Set Error-Counter-Max (Value) = 10 (Clock Hour Time check errors)

If ERROR-TYPE = 2, Set Error-Counter-Max (Value) = 12 (Database Records check errors)

If ERROR-TYPE = 3, Set Error-Counter-Max (Value) = 14 (DBRecord Column check errors)

If ERROR-TYPE = 0, 4-9, Set Error-Counter-Max (Value) = 20 (Error-Counter-Max (VALUE) errors)

CHECK-ERROR-LIGHT-COUNT

Turn-On-Lamp "DitMS" (10 ms Lamp On)

Turn-Off-Lamp "Inter-CharacterMS" (70 ms Lamp off)

If Error-Counter-Max (Value) = 1 to Error-Counter-Max (Value),
Set Error-Counter-Max (Value) = Error-Counter-Max (VALUE) - 1 (Decrement Error-Counter), Goto CHECK-ERROR-LIGHT-COUNT (Next Dit Loop).

If Error-Counter-Max = 0, Reset Error-Counter-Max (Value) = Original saved Error-Counter-Max (Value)),
Call LAMP-OFF-140MS-ROUTINE (Turn Lamp Off 140 ms), Goto ERROR-LAMP-ROUTINE (Original Max Value Continous-Loop).


LAMP-OFF-140MS-ROUTINE

Turn Lamp Off (140 ms)

GoSub RETURN


START ABC-SERIES-LIGHTS-ROUTINE:

READ DATABASE1 (Record-1, "AthruZ")

(Call MySQL DB Routine, Get Results)

If Record-Not-found, Set ERROR-TYPE = 2, then Goto ERROR-LAMP-ROUTINE

If Record-found, Goto CHECK-COLUMN(N)


CHECK-COLUMN(N)

Read Column(N)

If Column(N) Data =

Empty,0,5-8, Set ERROR-TYPE = 3, Goto ERROR-LAMP-ROUTINE

1 GoSub DITMS-Routine (10 ms Lamp On)

2 GoSub DASHMS-Routine (30 ms Lamp On)

3 GoSub INTER-CHARACTERMS-Routine (30 ms Lamp Off)

4 GoSub INTER-WORD-SENTENCESMS-Routine (70 ms Lamp Off)

9 RESET Column(N) = 1, Reset HOUR-INTERRUPT-CHECK = 0 (Reset CLOCK-CHECK-FLAG to Zero),
Goto CLOCK-CHECK (End of DBRecord Columns, Start Over!)


DitMS-Routine (10 ms Lamp On)

Turn On Lamp (10 ms timer)

Turn Lamp Off (10 ms, Inter-dit/dash Lamp Off Timer)

Column(N) = Column(N) + 1

Goto CHECK-COLUMN(N)


DashMS-Routine (30 ms Lamp On)

Turn On Lamp (30 ms timer)

Turn Lamp Off (10 ms, Inter-dit/dash Lamp Off Timer)

Column(N) = Column(N) + 1

Goto CHECK-COLUMN(N)


Inter-CharacterMS-Routine (30 ms Lamp Off)

Turn Off Lamp (30 ms timer)

Column(N) = Column(N) + 1

Goto CHECK-COLUMN(N)


Inter-Word-SentenceMS-Routine (70 ms Lamp Off)

Turn Off Lamp (70 ms timer)

Column(N) = Column(N) + 1

Goto CHECK-COLUMN(N)


GREETING-MESSAGE-ROUTINE

READ DATABASE1 (Record-2, "Greetings")

(Call MySQL DB Routine, Get Results)

If Record-Not-found, Set ERROR-TYPE = 2, then CALL ERROR-LAMP-ROUTINE

If Record-found, Goto CHECK-COLUMN(N)


HARDWARE LOGIC

tbd


Hardware Wiring and Components

tbd


END OF Arduino "Blinking Lighthouse" Programming Logic Psuedo-Code Overview (Draft 1).
rph (Originated: 4:50pm 31Dec2019).

No.
Still don’t understand.

Apart from the zero-origin indexing. You got that bit right

I want to use a table type record solution so I can change the sentence easily. Also, I to try to code using small routines, so I dont have to repeat logic (just change / add logic flags).

What is “the sentence”?
A fine?
A term in prison?
Community service?

The goal of the application is to constantly blink an LED(s) at an interval of say 2 seconds ON, and 4 seconds OFF (Like a light house). Except at every 15 minutes (ex 1:15, 1:30, 1:45) send out a morse code blinking light sequence of all 24 alphabet characters "A" thru "Z" (Record table 1). And, at the top of the hour, send a different unique Sentence (using a second table record 2), all in in morse code of course.

All I have to do is change any of the two variable length records to change the sentences I am sending out.

all 24 alphabet characters "A" thru "Z"

Which 2 are you planning to do without ?

The sentence could be "Glad you are here" or "Welcome to the Delta River", etc...

I can change the sentence at-will by just changing the elements within the table record.
The elements are the morse code which contain: dits (1), and dahs (2), End of dit/dah short Silence (3), End of Word long Silence (7), and End of Record Marker (9).

You ask which 2 am I planning to without? I hope none of my logic goals or two records....Not sure why I have to choose?

Btw This blog says I can only post every 5 minutes, since Im a newbie, so I had to delay in this post:

"Unable to publish the post. Please notice you can only post once every 5 minutes and only edit posts after 30 seconds. Once you reach 100 published posts this limit will be removed."

It might be simpler to use a plain old string like

char greet="Greetings from...

and step through it. Start at the beginning and send the morse for 'G', with appropriate timing/spacing, then 'R', and so on. This way you'd only need a table/array for the twenty-six letters, and whatever punctuation, numbers, etc.

It'd certainly be easier editing.

Edit: Looks like somebody's already done it - GitHub - ccannon94/morse-code-arduino-library: This repository includes a library to send Morse Code messages to a device (like an LED) connected to Arduino Uno pin 13.

Oh I get it, oooops, 26 characters.... Who needs those Zs and X's anyway. lol

The sentences are stored in the table records as Morse Code (blinking lights) element logic sequences, not "alphanumeric character" for printing/display!

You ask which 2 am I planning to without? I hope none of my logic goals or two records....Not sure why I have to choose?

How many letters are there in the alphabet ?

DougP, are you saying to set up an array (in C++ format of course, which I will find out the format)

Key, element,element,element,.....
A,1,2
B,2,1,1,1
C,2,1,2,1
etc.

and, create a string "Hello from Delta River"?

Can you grab individual Letters within a String (L = L+1)?
(The string can be of any length depending on the sentence used.)

If you can, then yes, I could do an array lookup for each individual letter grabbed from the string, and then grab the appropriate dits(1s) and Dahs(2s) from the array, for logic decisions.

Does C++ Arrays have a set length format and a maximum of elements allowed within an Array row (i.e. Key, plus 7 elements maximum for each key)?

If you have to define the array length for each row, would you use "," or, ",(blank), for each unused elements withing the array row (ie: A,1,2,,,,. or B,2,1,1,1, , , .)

Radiobiker:
DougP, are you saying to set up an array (in C++ format of course, which I will find out the format)

Key, element,element,element,.....
A,1,2
B,2,1,1,1
C,2,1,2,1
etc.

and, create a string "Hello from Delta River"?

Pretty much, except the table will not have 'A - Z' in it. The ( two dimensional ) table will have only the values needed to generate the actual Morse characters. Make a copy of a message character and send that to a function. The function massages the letter/character to arrive at an 'index' into an array - this index functions like your C, for example. At index two is the sequence of values that represent a Morse C; 2, 1, 2, 1 or whatever. The function reads these and generates the timing and on/off signal for the LED.

Radiobiker:
Can you grab individual Letters within a String (L = L+1)?
(The string can be of any length depending on the sentence used.)

Indeed. A C-style string *is * an array. You can access the elements like any other array.

Radiobiker:
Does C++ Arrays have a set length format and a maximum of elements allowed within an Array row (i.e. Key, plus 7 elements maximum for each key)?

An array tutorial.

Radiobiker:
If you have to define the array length for each row, would you use "," or, ",(blank), for each unused elements withing the array row (ie: A,1,2,,,,. or B,2,1,1,1, , , .)

Make the array size for each character (A - Z, etc.) six. This will hold the longest sequence plus a terminator. So 'S' would be "111". Since it's a character array the compiler will automatically append a \0 null terminator. Step through this array doing the dits and dahs and exit when a \0 is seen.

I did not closely examine the github link I posted but, using that library, or similar, it may be possible to leapfrog all this nitty gritty stuff and just start sending Morse.

Thank you DougP, Helobob, AWOL, wildbill, and Perry for all of your help so far!

I did get my two books today from Amazon: "C++ Primer" by Lippmann, Lajoie, and Moo (Fifth Edition, 2013... I think a newer Sixth Edition is coming out in October 2020!); and, "A Tour of C++" by Bjarne Stroustrup (inventor of C / C++) (Second Edition, 2018)... This reading oughta to keep me up at nights for a while...