Menu

Make notes

Peter Jakacki

Recently I was doing a zoom presentation on TAQOZ. One of the simple things I was showing was a one-liner, that is all the code fits onto one line and executes immediately when you hit enter. These are useful for quick tests.

Then I took one line and defined a new word to be added to the Forth dictionary. Normally any word you type in a Forth command line is delimited by spaces or tabs or CR and Forth will search its dictionary for an exact match which if found will normally then execute the code associated with that dictionary entry. If it doesn't find a match it then tries to convert it to a number if possible and if so, it then pushes that number onto the top of the data stack. All parameters and pointers and results are passed back and forth by means of the data stack.

Anyway, I called this word DEMO which when typed or implicitly called from any other code, will run its code and return. Here is that code except I call it NOTES and instead of embedding the pin number for audio output, I allow that to be passed via the stack:

pub NOTES ( pin -- )   PIN 3000 100 DO I HZ 50 ms 100 +LOOP MUTE ;

Now I have an amplified speaker connected to P6 and P7 so that when I type 6 NOTES<cr> it produces a series of gliding notes starting at 100Hz, holding it for 50 ms before stepping up another 100Hz until it reaches the limit of 3000 where it then exits the loop and in this case MUTEs the audio output.</cr>

You can try this in the TAQOZ ROM, just connect any serial terminal at any baud rate, typically 115200 baud, type the two character auto-baud sequence " > space " followed by an escape to enter TAQOZ in ROM. (The P2 goes to sleep after a few minutes if it doesn't boot anything, so you might have to press the reset again to wake it up).
This is what I see:

x
  Cold start
-------------------------------------------------------------------------------
  Parallax P2  .:.:--TAQOZ--:.:.  V1.1--v33h         190219-1900
-------------------------------------------------------------------------------
TAQOZ# 

Hit the enter key and TAQOZ will respond with "--- ok" and reprompt on a new line (CR+LF). This simply indicates TAQOZ is responding to your input.
Now copy and paste the NOTES line of code shown above and perhaps hit enter if necessary and then you will see the "--- ok" response. If you have a speaker or transducer connected to P6 then type "6 NOTES" and you will hear the gliding tone.

Didn't Work?
Perhaps it said "6NOTES ???" which means there is no such word in the dictionary. Make sure you have at least one space between the 6 and NOTES.

Still didn't work?
If it says "NOTES ???" then it is quite possible that you made a mistake typing in NOTES if you didn't paste it, or that TAQOZ has been reset since and lost it.

If you want to save this for next time you boot up then type BACKUP which will backup the whole TAQOZ image into Flash. Although TAQOZ in ROM is not designed to automatically boot, you can restore the Flash image once you are back into TAQOZ using RESTORE or simply a ^R (control R) which also restarts TAQOZ from this restored image. Btw, the image is saved in the $F.0000 area of the Flash chip as a 64kB binary.

HOW DOES IT WORK:

pub NOTES       Create a new public word called NOTES, and start compiling the following code
( pin -- )      ( is a comment up to the matching ), in this case a stack effects comment   
                with "pin" as value on the stack when entering, without returning any results.
PIN             Latches the value supplied as the destination for any further PIN type operations.
3000            Not a word, but recognized as the number 3000 which is pushed onto the stack 
100             The number 100 is pushed onto the stack over the top of the 3000
DO              Marks the beginning of a loop and takes a starting index (100) and a stop limit (3000)
  I             Returns the value of the current Index starting from 100 (on top of the stack)
  HZ            HZ takes the value from the stack and sets the current PIN to output a matching NCO frequency
  50            50
  ms            will delay 50ms before continuing, long enough to hear a distinct note.
  100           the Hz value we want to step up each time through the loop (100Hz)
+LOOP           Increment the index by the value supplied and loop again until the limit is reached
MUTE            Now to stop that infernal racket, MUTE will simply reset the smartpin function of the pin
;               Exit and return (also completes this word when it is first being created)

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.