HP 40gs HP 39gs_40gs_Mastering The Graphing Calculator_English_E_F2224-90010.p - Page 294
The Prompt commands, BEEP <frequency>;<duration>, CHOOSE <variable>;<title>;<menu option1>;….
UPC - 882780045217
View all HP 40gs manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 294 highlights
The Prompt commands BEEP ; This will use the piezo crystal in the calculator to create a sound of the specified frequency for the specified duration (in seconds). The resulting frequency is not terribly accurate, varying by up to 5% from one calculator to the next and depending also on the temperature. If you want accuracy then use a piano! The volume is also not very loud because of concerns with interruptions to tests and examinations. Any frequency can be produced using the BEEP command but most people are interested in using it to play tunes. The information below will help with this. The frequencies of the twelve semi-tone jumps in the normal Western harmonic scale form a geometric sequence, and since the ratio from C to C' is 2, the ratio for each semi-tone must be 12 2 . The standard frequency used in tuning instruments is usually 440 cycle/sec for the note A. Since much of the simple music used by students is written using the scale of C, we use 440 /(12 2)9 to find the frequency of C as 261.6 cycles/sec. We can use this to form a standard 'header' for any program we want to use to play music. The header shown right in the rounded box sets up the scale of C major. The code which then follows plays the first two bars of the tune "Strangers in the Night". In this header, the duration of a note (T) is set to 0.5 seconds. It is easy to change the tempo of the music by adjusting this. In this case you may find that the music sounds a little better with T set to 0.55 or 0.6 seconds. T is a crotchet, T/2 a quaver etc. CHOOSE ;;;.... This command pops up a menu with the title specified and with however many options follow. The number of the menu option highlighted when the user presses is returned in the variable. It is particularly important to the use of this command to realise that the initial value of the variable before the CHOOSE statement determines which option is initially highlighted. This value must be a valid one in the sense that it must refer to one of the lines in the list you have defined. Assigning an initial value outside the range of the menu may crash the program. In particular, the default value for any variable is zero and this is not a legal list line so failing to pre-define a value may crash your program. If the user presses then a value of zero is returned but the program will still continue to execute from that point unless you include code to check for the cancellation and take action to terminate it or take some other action. 294