Showing posts with label music. Show all posts
Showing posts with label music. Show all posts

Saturday, December 13, 2025

RPN: HP 42S, DM42, Free 42 Tones, Column Vectors, and Songs

RPN: HP 42S, DM42, Free 42 Tones, Column Vectors, and Songs



Making Music of 10 Tones


The HP 42S, and subsequently, the Free42 app, the Plus42 app, and the Swiss Micros DM42, along with the HP 41C and DM41X. Let’s focus on the HP 42S version.


Tone is followed by:


* a single-digit integer (0-9)

* a tone number called indirectly through a stack level (X, Y, Z, T) or a memory register


I asked on the MoHPC (Museum of HP Calculators) forum what scale that the 42S used for the tones. According to Thomas Okken, who programmed the Free42 app, the tones come from the A major scale, with the note A3 called from TONE 1. TONE 0 played the E3 note. Thank you, Thomas!


https://www.hpmuseum.org/forum/thread-23678-post-205315.html#pid205315


The program CTONE plays a collection of tones that is stored in a single-column matrix named MCOL. An example of a collection of tones


[ [ 1 ]

[ 3 ]

[ 5 ]

[ 1 ]

[ 3 ]

[ 5 ]

[ 7 ]

[ 7 ]

[ 7 ]

[ 7 ]

[ 1 ]

[ 3 ]

[ 5 ]

[ 1 ]

[ 3 ]

[ 5 ]

[ 7 ]

[ 8 ]

[ 9 ]

[ 7 ] ]


CTONE: plays tones of the column vector MCOL


00 { 44-Byte Prgm }

01▸LBL "CTONE"

02 INDEX "MCOL"

03 WRAP

04 RCL "MCOL"

05 DIM?

06 X<>Y

07 3

08 10↑X

09 ÷

10 +

11 STO 00

12▸LBL 00

13 RCLEL

14 TONE IND ST X

15 I+

16 ISG 00

17 GTO 00

18 RTN

19 .END.


The following program, CRVCT, creates a matrix with one column named MCOL.


CRVCT: create a vector MCOL


00 { 79-Byte Prgm }

01▸LBL "CRVCT"

02 "SIZE?"

03 PROMPT

04 STO 01

05 1

06 DIM "MCOL"

07 X<>Y

08 3

09 10↑X

10 ÷

11 +

12 STO 00

13 INDEX "MCOL"

14 WRAP

15 ALL

16▸LBL 00

17 "ROW "

18 RCL 00

19 IP

20 ARCL ST X

21 ├"?"

22 PROMPT

23 STOEL

24 ISG 00

25 GTO 01

26 GTO 02

27▸LBL 01

28 I+

29 GTO 00

30▸LBL 02

31 RCL "MCOL"

32 FIX 04

33 RTN

34 .END.


Source


“HP 42S TONE” Museum of HP Calculators. https://www.hpmuseum.org/forum/thread-23678-post-205315.html#pid205315 Retried June 9, 2025.


Have fun,


Eddie


All original content copyright, © 2011-2025. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

The author does not use AI engines and never will.

Saturday, July 18, 2020

HP 41C and HP 42S (also Free42/DM42): Random Tone Generator

HP 41C and HP 42S (also Free42/DM42): Random Tone Generator

Tones

The program RTONE generates a set of random tones (0 through 9).   Since the HP 41C (without additional modules) does not have a pseudo random number generator, a simple generator is included, particularly (π + x0)^5 = x1.

The HP 42S has a random number generator and it is used in its program.  Performance of RTONE is increased, and is really fast on the Free42 and Swiss Micros DM42. 

The command TONE can refer to indirect registers (stack X for this program) and accepts real numbers between 0 to 9.9999999.  TONE ignores the fractional part.

HP 41C Program: RTONE

01 LBL^T RTONE
02 ^T N?
03 PROMPT
04 INT
05 STO 03
06 ^T SEED?
07 PROMPT
08 LBL 00
09 PI
10 +
11 5
12 Y↑X
13 10
14 MOD
15 TONE IND X
16 DSE 03
17 GTO 00
*END*

HP 42S/Free42/DM42 Program:  RTONE

00 {37-Byte Prgm}
01 LBL "RTONE"
02 "SEED?"
03 PROMPT
04 SEED
05 "N?"
06 PROMPT
07 IP
08 STO 03
09 LBL 00
10 RAN
11 10
12 *
13 TONE IND ST X
14 DSE 03
15 GTO 00
16 END

A fun, little musical program.

Eddie

All original content copyright, © 2011-2020.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Monday, January 28, 2019

HP 71B: Linear Regression, Open Channel, Sunrise/Sunset, Musical Mini-Piano

HP 71B:  Linear Regression, Open Channel, Sunrise/Sunset, Musical Mini-Piano

Feel free to use this pic whenever it's Friday.  Even if it's Monday.  :) 


Linear Regression with a User Keyboard

This program creates a user keyboard with the following keys defined:

[ I ]  Clears the statistics array and variables
[ A ]  Add a data point X,Y: the sample size is shown
[ D ]  Delete a data point X,Y:  the sample size is shown
[ M ] Sample Mean for X and Y data.  Press CONT for mean of Y values.
[ S ] Sums for X and Y data.  Press CONT for sum of Y values.
[ E ]  Standard Deviation for X and Y data.  Press CONT for standard dev. of Y values.
[ R ]  Execute Linear Regression.  A = intercept, B = slope, correlation is calculated, fit to the line Y = A + B*X
[ H ]  Help:  cycles what all the keys do
[ X ] Clears all the user keys, prepares you to go to the next program

PROGRAM STATLIN
689 bytes, 1/26/2019

10 DEF KEY "I", 'RUN 110'
20 DEF KEY "A", 'RUN 200'
30 DEF KEY "D", 'RUN 300'
40 DEF KEY "M", 'RUN 400'
45 DEF KEY "S", 'RUN 440'
50 DEF KEY "E", 'RUN 500'
60 DEF KEY "R", 'RUN 600'
70 DEF KEY "X", 'RUN 700'
75 DEF KEY "H", 'RUN 750'
80 USER ON
90 END

110 DESTROY S,A,B,X,Y,H$,I
120 STAT S(2) @ PRINT "ALL CLEAR"
130 END

200 INPUT "+ X,Y:";X,Y
210 ADD X,Y & DISP "N=";TOTAL(0)
220 END

300 INPUT "- X,Y:";X,Y
310 DROP X,Y & DISP "N=";TOTAL(0)
320 END

400 PRINT "X-BAR=";MEAN(1) @ PAUSE
420 PRINT "Y-BAR=";MEAN(2)
430 END

440 PRINT CHR$(28);"X=";TOTAL(1) @PAUSE
450 PRINT CHR$(28);"Y=";TOTAL(2)
460 END

500 PRINT "sX:";SDEV(1) @ PAUSE
510 PRINT "sY:";SDEV(2)
520 END

600 LR 2,1,A,B
610 PRINT "INT=";A @ PAUSE
620 PRINT "SLP=";B @ PAUSE
630 PRINT "r=";CORR(2,1) @ PAUSE
640 PRINT "Y=";A;"+";B;"X"
650 END

700 PURGE KEYS @ USER OFF
710 PRINT "EXIT COMPLETE"

750 FOR I=1 TO 8
760 READ H$ @ PRINT H$ @ WAIT 1
770 DATA "I: CLEAR","A: ADD","D: DEL","M: MEAN","S: SUMS","E: SDEV","R: A+BX","X: EXIT"
780 NEXT I
790 PRINT "READY." @ END

Example to try:

Data:  X,Y
-5.56, 0.79
-4.30, 0.84
1.86, 1.93
2.24, 2.01
3.95, 2.26

To add data:  (in USER mode) [ A ] -5.56, 0.79 [END LINE] (repeat for all data points)

Results:  n = 5

Mean:
[ M ]  "X-BAR=" -0.362  [ f ] [ + ] (CONT) "Y-BAR=" 1.566

Sums:
[ S ]  "∑X=" -1.81 [ f ] [ + ] (CONT) "∑Y=" 7.83

Standard Deviations:
[ E ] "sX=" 4.26696847891 [ f ] [ + ] (CONT) "sY=" 0.696512742166

Linear Regression:
[ R ] "INT=" 1.62489805306  [ f ] [ + ] (CONT)
"SLP=" 0.162701804029 [ f ] [ + ] (CONT)
"r=" 0.996741950615 [ f ] [ + ] (CONT)
"Y=1.6248905306 + 0.162701804029 X"

Open Channel Parameters

Source: 

Michael R. Lindberg, PE  Civil Engineering Reference Manual for the PE Exam 11th Edition  Professional Publications Inc., Belmont, CA  2008  ISBN-13:  978-1-59126-129-2

The program OPENFLOW calculates the following:

Area
Wetted Perimeter
Hydraulic Radius
Hydraulic Depth
Uniform Section Factor

of conductors of four shapes: rectangle, trapezoid, triangle, and circle.



PROGRAM OPENFLOW
781 bytes, 1/25/2019

10 DESTROY K,D,B,P,R,T,H,W
20 DEGREES
30 DISP "1. RECTANGLE" @ WAIT 1
40 DISP "2. TRAPEZOID" @ WAIT 1
50 DISP "3. TRIANGLE" @ WAIT 1
60 DISP "4. CIRCLE" @ WAIT 1
70 DISP "ELSE. REPEAT" @ WAIT .5
80 INPUT "CHOICE (1-4,E):"; K
90 IF K=1 THEN 1010
100 IF K=2 THEN 2010
110 IF K=3 THEN 3010
120 IF K=4 THEN 4010
130 GOTO 30

1010 INPUT "WIDTH,DEPTH:";W,D
1020 A=D*W @ P=2*D+W @ R=A/P
1030 H=A/W @ S=A*R^(2/3)
1040 GOTO 5010

2010 INPUT "DEPTH:";D
2012 INPUT "WIDTH-LONG:";W
2014 INPUT "WIDTH-SHORT:";B
2016 INPUT "ANGLE:";T
2020 A=D*(B+D/TAN(T)) @ P=B+2*(D/SIN(T)) @ R=A/P
2030 H=A/W @ S=A*R^(2/3)
2040 GOTO 5010

3010 INPUT "WIDTH:";W
3012 INPUT "DEPTH:";D
3014 INPUT "ANGLE:";T
3020 A=D^2/TAN(T) @ P=2*D/SIN(T) @ R=A/P
3030 H=A/W @ S=A*R^(2/3)
3040 GOTO 5010

4010 INPUT "RADIUS:";R
4012 INPUT "ANGLE:";T @ T=PI*T/180
4014 RADIANS
4020 A=1/8*(T-SIN(T))*D^2 @ P=T*D/2 @ R=A/P
4030 H=A/D @ S=A*SQR(D)
4040 GOTO 5010

5010 PRINT "AREA=";A @ PAUSE
5020 PRINT "WET PERIM.=";P @ PAUSE
5030 PRINT "HYD. RADIUS=";R @ PAUSE
5040 PRINT "HYD. DEPTH=";H @ PAUSE
5050 PRINT "SECTION FACTOR=";S
5060 END


Approximate Time of Sunrise and Sunset

Source:

Hewlett Packard "HP-65 Aviation Pac" 1974

The program SUNTIME approximates the time of sunset and sunrise based on a date in a general 365-day calendar, the person's location (longitude (east is negative, west is positive) and latitude (north is positive, south is negative)), and the time zone.

Time Zone Table (United States/Mexico/Canada) 
Hours from GMT:
Hawaii:   Standard and Daylight: -10
Alaska:  Standard: -9, Daylight: -8
Pacific:  Standard: -8, Daylight: -7
Mountain: Standard: -7, Daylight: -6
Central: Standard: -6, Daylight: -5
Eastern: Standard: -5, Daylight: -4

Program SUNTIME
494 bytes, 1/24/2019

10 DESTROY T,E,D,A,Z,G,C
11 DESTROY S,S1,S2,S3
12 DESTROY O1,O2,O3,O,U1,U2,U3,U
14 DEGREES
16 INPUT "MONTH: ";M
20 INPUT "DAY: ";D
26 INPUT "LONG (E/W):D,M,S:";O1,O2,O3
27 O=O1+O2/60+O3/3600
30 INPUT "LAT (S/N):D,M,S:";U1,U2,U3
32 U=U1+U2/60+U3/3600
35 INPUT "TIME ZONE:";Z
40 T=.988*(D-1+30.3*(M-1))
45 E=.123*COS(T+87)-1/6*SIN(2*T+20)
50 C=-23.439*COS(T+10)
55 S=(O-ACOS(-TAN(C)*TAN(U)))/15-E+12+Z
57 S1=IP(S)
59 S2=IP(FP(S)*60)
61 S3=FP(FP(S)*60)*60
65 DISP "Sunrise: ";S1;":";S2;":";S3 @ PAUSE
75 N=(O+ACOS(-TAN(C)*TAN(U)))/15-E+12+Z
77 N1=IP(N)
79 N2=IP(FP(N)*60)
81 N3=FP(FP(N)*60)*60
85 DISP "Sunset: ";N1;":";N2;":";N3

Example:
Time:  January 26  (Month = 1, Day = 26)
Place:  Farifield, CA:   38°15′28″N 122°3′15″W
Time Zone: -8 (Standard)

Inputs:
MONTH: 1
DAY: 26
LONG: 122,3,15
LAT: 38,15,28
TIME ZONE: -8

Results:
Sunrise: 7 : 24 : 19.09497708
Sunset: 17 : 16 : 17.62419468

Musical Mini-Piano

Key map:

[ A ]:  A
[ W ]:  A#
[ S ]: B
[ D ]: C
[ R ]: C#
[ F ]: D
[ T ]: D#
[ G ]: E
[ H ] : F
[ U ]: F#
[ J ]: G
[ I ]: G#
[ K ]: A (higher octave)

[ O ]: One octave higher
[ L ]:  One octave lower

[ P ]: Double the length of the note
[ = ]: Halve the length of the note

[ X ]:  Exit, clears all the user keys

Default octave:  A4 (220 HZ) to A5 (440 Hz)
Default note length:  1/4 second

Program PIANO
743 bytes, 1/27/2019

100 DESTROY A,N,P
110 A=2^(1/12) @ N=0 @ P=0
112 DEF KEY "A", 'BEEP 220.0*2^N,.25*2^P': ! A
114 DEF KEY "W", 'BEEP 233.1*2^N,.25*2^P': ! A#
116 DEF KEY "S'", 'BEEP 246.9*2^N,.25*2^P': ! B
118 DEF KEY "D", 'BEEP 261.6*2^N,.25*2^P': ! C
120 DEF KEY "R", 'BEEP 277.2*2^N,.25*2^P': ! C#
122 DEF KEY "F", 'BEEP 293.7*2^N,.25*2^P': ! D
124 DEF KEY "T", 'BEEP 311.0*2^N,.25*2^P': ! D#
126 DEF KEY "G", 'BEEP 329.6*2^N,.25*2^P': ! E
128 DEF KEY "H", 'BEEP 349.2*2^N,.25*2^P': ! F
129 DEF KEY "J", 'BEEP 392.0*2^N,.25*2^P': ! G
130 DEF KEY "U", 'BEEP 370.0*2^N,.25*2^P': ! G#
132 DEF KEY "I", 'BEEP 415.3*2^N,.25*2^P': ! F
134 DEF KEY "K", 'BEEP 440.0*2^N,.25*2^P': ! A
136 DEF KEY "O", 'N=N+1@ PRINT "OCTAVE UP" ':
138 DEF KEY "L", 'N=N-1 @ PRINT "OCTAVE DOWN" ':
140 DEF KEY "P", 'P=P+1 @ PRINT "NOTE x2" ':
142 DEF KEY "=", 'P=P-1 @ PRINT "NOTE /2" ': 
144 DEF KEY "X", 'RUN 400':
146 USER ON
148 END
400 DESTROY A,N,P
410 PURGE KEYS
420 USER OFF
430 PRINT "EXIT COMPLETE"
440 END

Eddie

All original content copyright, © 2011-2019.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.

Monday, July 4, 2016

TI-65 Programs Part II: Reynolds Number/Hydraulic Diameter, Escape Velocity, Speed of Sound/Resonant Frequencies in an Open Pipe

TI-65 Programs Part II:  Reynolds Number/Hydraulic Diameter, Escape Velocity, Speed of Sound/Resonant Frequencies in an Open Pipe

This is the second part of programs for the TI-65 this Fourth of July. 



TI-65 Reynolds Number/Hydraulic Diameter

This program utilities the two keyboard labels:

[F1]:  Calculates the Reynolds Number
[F2]:  Calculates the Hydraulic Diameter of a Rectangular Duct

Formula for the Reynolds Number:

Re = (v * DH)/w

v = velocity of the fluid (liquid or gas)
DH = hydraulic diameter
w = kinematic viscosity

The hydraulic diameter of the following ducts:

Tubular pipes:  DH = diameter of the tube
Annulus:  DH = large radius – small radius
Square Duct:  DH = length of one side
Rectangular Duct:  DH = (2*a*b)/(a + b);  a, b are the lengths of the sides

Program:
CODE
STEP
KEY
COMMENT
2nd 53.53
00
LBL F1
Starts F1, have DH on the display (meters)
38
01
*

51
02
R/S
Prompt: velocity of fluid (m/s)
28
03
÷

51
04
R/S
Prompt: kinematic viscosity (m/s)
39
05
=

-15
06
INV EE
Remove Engineering notation
2nd 52
07
RTN
End F1
2nd 53.54
08
LBL F2
Starts F2: have a on display (m)
12.0
09
STO 0

38
10
*

51
11
R/S
Prompt for b
12.1
12
STO 1

38
13
*

2
14
2

28
15
÷

16
16
(

13.0
17
RCL 0

59
18
+

13.1
19
RCL 1

17
20
)

39
21
=
DH of rectangular duct
2nd 52
22
RTN
End F2


TI-65 Reynold’s Number

Input: hydraulic diameter (m) [F1], velocity of the fluid (m/s) [R/S], kinematic viscosity (m/s) [R/S]
Output:  Reynolds number (dimensionless)

Hydraulic Diameter of a Rectangular Duct
Input:  a (m) [F2], b (m) [R/S]
Output:  DH (m)

Test 1:  Tubular Pipe Duct of hydraulic diameter of 3.5 in.  The fluid is water at 68°F (20°C), flowing at 0.5 m/s.  The kinematic viscosity of water of 20°C is 1.004 *10^-6 m/s.

Input:  3.5 [3rd] [in-cm] [ ÷ ] 100 = [ F1 ], 0.5 [R/S], 1.004 [EE] 6 [+/-] [R/S]
Output:  44,272.90837

Test 2:  Rectangular Duct where a = 1.27 m and b = 0.508 m (50 in x 20 in).  The fluid is air at 60°F (about 15.6°C), flowing at 0.5 m/s.  The kinematic viscosity of air at 15.6°C is 1.58 * 10^-4 m/s.

Input:  1.27 [F2], 0.508 [R/S]
Result:  0.725714286 m  (hydraulic diameter), keep this number in the display
Input:  [F1], 0.5 [R/S], 1.58 [EE] 4 [+/-] [R/S]
Result: 2296.564195  (Reynolds Number)

TI-65 Escape Velocity

The formula for the escape velocity from a planet is:

v = √(2*G*m/r)

v = escape velocity (m/s)
G = University Gravitational Constant = 6.67384 * 10^-11 m^3/(kg*s^2)
m = mass of the planet (kg)
r = radius of the planet (m)

Note that 2*G = 1.334768 * 10^-10 m^3/(kg*s^2)

Program:
CODE
STEP
KEY
COMMENT
2nd 16
00
2nd ENG
Start with mass, set Engineering mode
38
01
*

1
02
1
Enter 2*G
57
03
.
Decimal Point
3
04
3

3
05
3

4
06
4

7
07
7

6
08
6

8
09
8

15
10
EE

1
11
1

0
12
0

58
13
+/-

28
14
÷

51
15
R/S
Prompt for radius
39
16
=

33
17

51
18
R/S
Display escape velocity


Input:  mass of the planet (kg) [RST] [R/S], radius of the planet (m) [R/S]
Output:  escape velocity (m/s)

Test 1:  Earth (m = 5.97219 * 10^24 kg, r = 6.378 * 10^6 m)
Input: 5.97219 [EE] 24 [RST] [R/S], 6.378 [EE] 6 [R/S]
Result:  ≈ 11.179E3 (about 11,179 m/s)

Test 2:  Jupiter (m = 1.89796 * 10^27 kg, r = 71.492 * 10^6 m)
Result:  ≈ 59.528E3 (about 59,528 m/s)

 TI-65 Speed of Sound/Resonant Frequencies in an Open Pipe

Formulas:

Speed of Sound (m/s):  v = t*0.6 + 331.4
Where t = temperature (°C)

Resonant Frequencies in an Open Pipe:  fn = n*v/(2*L)
Where fn = frequency (Hz), v = speed of sound (m/s), L = length of pipe (m), n = 1, 2, 3…
If n = 1, then fn is the fundamental frequency

Program:
CODE
STEP
KEY
COMMENT
2nd 53,53
00
LBL F1
Start Label F1
38
01
*

57
02
.
Decimal Point
6
03
6

59
04
+

3
05
3

3
06
3

1
07
1

57
08
.
Decimal point
4
09
4

39
10
=

2nd 52
11
RTN
End F1
2nd 53, 54
12
LBL F2
Start label F2
28
13
÷

13.1
14
RCL 1

28
15
÷

2
16
2

39
17
=

12.0
18
STO 0

1
19
1

12.3
20
STO 3
Counter
2nd 53.0
21
LBL 0
Start loop
13.3
22
RCL 3

2nd 51
23
PAUSE

38
24
*

13.0
25
RCL 0

39
26
=

51
27
R/S
Display fn
1
28
1

12.59
29
STO+

3
30
3
STO+ 3
13.3
31
RCL 3

-3rd 44
32
INV 3rd x>m
x≤m?
2
33
2
x≤R2?
2nd 54.0
34
GTO 0
If x≤R2, GTO LBL 0
13.2
35
RCL 2

2nd 52
36
RTN
End F2

Speed of Sound in Dry Air: 
Input:  Enter temperature in °C [F1]
Result:  Speed of sound (m/s)

Resonant Frequencies:
Store the length of the pipe (m): L [STO] 1
Store the upper limit:  n [STO] 2
Input: speed of sound (m/s) [F2], n flashes before frequency (Hz), press [R/S] to see other frequencies
The program finishes when n is displayed a second time.


Test:
Open pipe of 0.45, where the temperature of the air is 39°C (102.2°F).  Find out the first 3 resonant frequencies.

We’ll need the speed of air, but first, store the required constants:
0.45 [STO] 1, 3 [STO] 2

Next find the speed of air:
Input:  39 [F1]
Result:  354.8 m/s

Find the 3 resonant frequencies:
Input: (with 354.8 in the display) [F2]
Result:  1, 394.2222222 Hz  [R/S]  \\ fundamental frequency
2, 788.4444444 Hz [R/S]  \\ 2nd frequency
3, 1182.666667 Hz [R/S]  \\ 3rd frequency

Source:  Browne Ph. D, Michael.  “Schaum’s Outlines:  Physics for Engineering and Science”  2nd Ed.  McGraw Hill: New York, 2010


This blog is property of Edward Shore, 2016.



Trigonometry Reduction Formula and Solving Simple Arcsine and Arccosine Equations

Trigonometry Reduction Formula and Solving Simple Arcsine and Arccosine Equations Some Background and Periodic Reduction Formulas ...