Close

Groups

A project log for Pico Picow

A tiny handheld dev console, with a 12 button keypad, Pi Pico W inside, and 128x64 OLED.

gordonGordon 01/04/2025 at 23:340 Comments

Today I wrote the code for GROUPS, as I described in an earlier post that they are essentially functions that use the keywords G<n>  (n can be 0-99).

I was having issues if I wanted to call a group from inside a group, where the last group would think it was creating a new group, but I figured that out, and now it's working as it should. Some example code:

0K $Enter Your Name$
G0@ O 0K I 1K O$Hello$, 1K,$!$ @
G1@ G0 LG@
G1

This code demonstrates:

  1.  Storing a string into the KEYWORD "0K'
  2. Initializing the GROUP "G0", which does the following:
    1. Outputting retrieved KEYWORD 0K, which is the prompt for user
    2. Waiting for user input, which is stored in the KEYWORD "1K"
    3. A greeting as well as the users input is then output to user
  3. Initializing the GROUP "G1" which:
    1. Calls G0
    2. Loops G1

I figured out how to make GROUPS callable from within other groups when I was coding TGRK. When calling a GROUP, a list holds the return address from where that GROUP was called from. When the called group reaches it's ending "@" symbol, it pops the last address from the list, which will be in the right order, and sets the program counter to that address.

Below is an idea of several different ways we could write this code on the Pico Picow, either going for the most compact, or the most readable... keeping in mind 16 characters is the widest line that can be displayed on the screen:

0K$Enter Your Na
me$G0@O$Hello $,
1K,$!$@G1@O0KI1K
G0@G2@G1LG@G2

----------------

0K $Enter
    Your
    Name$
G0@
    O$Hello $,
    1K,
    $!$
@

G1@
    O 0K
    I 1K
    G0
@

G2@
    G1
    LG
@

G2

 To be able to format the code as above, I had to remove the feature where we can add whitespace by adding a space after the OUTPUT comma " O$Hi$, $there!$" will now output "Hithere!". I think that was a cool feature so I am going to look into some way of reintroducing it, but for now, just adding the space in the string literal or KEYWORD is enough.

I think next I will work on Conditional Operators.

Discussions