Sunday, May 18, 2025

Casio fx-CG100: The getkey command in Python

Casio fx-CG100: The getkey command in Python


The getkey command: A Demonstration


The fx-CG100 adds a command to its Casioplot module, the beloved getkey command. The getkey returns the key code of the last key pressed from the command’s execution. The getkey allows for custom keyboard, movement of characters, or easy input of menu choices.


The getkey code that is assigned to each key on the fx-CG100 is thankfully fairly simple: it is a combination of the row number and a column number. For instance, the key code 21 is assigned to the [SETTINGS] key while the key code 95 is assigned to the [EXE] key.


Some key codes include:

Left arrow (←)

23

Up arrow (↑)

14

OK key

24

Down arrow (↓)

34

Right arrow (→)

25

EXE

95

1 Key

81

2 Key

82

3 Key

83

4 Key

71

5 Key

72

6 Key

73

7 Key

61

8 Key

62

9 Key

63

0 Key

91


Other key assignments can be found in the manual under the getkey() command in the Casioplot section: https://support.casio.com/global/en/calc/manual/fx-CG100_1AUGRAPH_en/BONDSYlkjdoxxc.html#BONDSYhxeuohnh


Note that the [ ON ] and [ AC ] buttons have no key assigned to them and can not be used with the getkey command.


Example: Calculating Horsepower


The script, hp.py calculates horsepower by one of three sets of inputs:


Press [ 1 ] to input weight (pounds) and time (seconds).

Press [ 2 ] to input weight (pounds) and speed (mi/hr).

Press [ 3 ] to input RPM (revolutions per minute) and torque (foot-pounds).


Using Getkey for Menus

To set up the getkey, I first make a “choice variable”, such as ch, and set it to 0. The while loop contains the menu and does not end until the user presses [ 1 ], [ 2 ], or [ 3 ] (or [ AC ] to terminate the program).   


from casioplot import *


# setup

ch=0


# title screen

while ch==0:

  clear_screen()

  draw_string(0,0,"**HORSEPOWRER CALCULATOR**")

  draw_string(0,20,"**     Inputs Menu     **")

  draw_string(0,40,"1) weight, time",(192,0,0))

  draw_string(0,60,"2) weight, speed",(0,0,192))

  draw_string(0,80,"3) RPM, torque",(0,128,0))

  show_screen()

  k=getkey()

  if k==81:

    ch=1

  elif k==82:

    ch=2

  elif k==83:

    ch=3

  


# calculation

if ch==1:

  w=float(input("weight in lbs:  "))

  t=float(input("time in sec:  "))

  hp=w*(t/5.825)**(-3)

elif ch==2:

  w=float(input("weight in lbs:  "))

  s=float(input("speed in mph:  "))

  hp=w*(s/234)**3

elif ch==3:

  r=float(input("RPM:  "))

  t=float(input("torque (ft-lbs): "))

  hp=(r*t)/5252


clear_screen()

txt="{0:.5f} hp".format(hp)

draw_string(0,0,"Horsepower=")

draw_string(0,20,txt,(192,0,0))

draw_string(0,100,"Press AC to exit.",(0,128,128))

show_screen()


Notes: The getkey is meant to work with the Casioplot commands. Instead of the built-in print command, we use draw_string and show_screen commands to display output. The plus here is that we can have text in color. The show_screen is displayed until either the [ EXE ] or the back buttons is pressed.


The input command returns us to the Shell and is not part of the Casioplot commands.


Source for the Formulas Used: 


Inch Calculator “Engine Horsepower Calculator”. Calc Hub, LLC. 2025. https://www.inchcalculator.com/engine-horsepower-calculator/ Retrieved May 5, 2025.


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.


Saturday, May 17, 2025

TI-84 Plus CE: Rafter Multipliers and Roof Area

TI-84 Plus CE: Rafter Multipliers and Roof Area



Introduction


Rafter multipliers are a quick way to calculate the area of a roof. All that is needed are three measurements:


(1) The width of a house

(2) The length of a house, including eaves and lengths of overhangs

(3) The pitch of the roof. The pitch the rise of the roof in inches over a run of 12 inches.


It is assumed that we have a simple roof and the area of the house is rectangular. Even in more complex cases, we can use the multipliers come up with a good approximation.



Pitch = rise in inches / 12 inches


The area of the roof depends on the width, length, and pitch.


The area is approximated by:

roof area ≈ length * width * rafter factor


The common values are shown here:


Pitch (n in 12”)

Pitch (decimal – 3 places)

Rafter Factor (decimal -3 places)

2 in 12

0.167

1.014

3 in 12

0.250

1.031

4 in 12

0.333

1.054

5 in 12

0.417

1.083

6 in 12

0.500

1.118

7 in 12

0.583

1.158

8 in 12

0.667

1.202

9 in 12

0.750

1.250*

10 in 12

0.833

1.302

11 in 12

0.917

1.357

12 in 12

1.000

1.413

13 in 12

1.083

1.474

14 in 12

1.167

1.537

15 in 12

1.250

1.601

16 in 12

1.333

1.667

17 in 12

1.417

1.734

18 in 12

1.500

1.803

19 in 12

1.583

1.875

20 in 12

1.667

1.948

21 in 12

1.750

2.010

22 in 12

1.833

2.083

23 in 12

1.917

2.167


* This was erroneously labeled as 1.357 on the Dewalt Construction Math Quick Check guide (see Sources). Several sources correctly has the value of 1.250.



Curve Fitting


What if I can fit a formula to the above data?


I used a TI-84 Plus CE to assist me with this.


First, we’ll use the quadratic regression with the data from the above table:


y = a * x^2 + b * x + c


The resulting coefficients:


a = 0.1867080745

b = 0.2897396951

c = 0.938

r^2 = 0.9992015789


That’s a pretty good fit.


What about the square root fit:


y = √(a * x^2 + b)


If we square both sides, we get:


y^2 = a * x^2 + b


This equation takes somewhat the form of the linear regression.


Let z = x^2 and t = y^2, then:


z = a * t + b


Pitch (n in 12”)

X = Pitch (decimal – 3 places)

Z = X^2 (approximate)

Rafter Factor (decimal -3 places)

T = Y^2 (approximate)

2 in 12

0.167

0.0278

1.014

1.0282

3 in 12

0.250

0.0625

1.031

1.063

4 in 12

0.333

0.1111

1.054

1.1109

5 in 12

0.417

0.1736

1.083

1.1729

6 in 12

0.500

0.25

1.118

1.2499

7 in 12

0.583

0.3403

1.158

1.341

8 in 12

0.667

0.4444

1.202

1.4448

9 in 12

0.750

0.5625

1.250*

1.5625

10 in 12

0.833

0.6944

1.302

1.6952

11 in 12

0.917

0.8403

1.357

1.8414

12 in 12

1.000

1

1.413

1.9966

13 in 12

1.083

1.1736

1.474

2.1727

14 in 12

1.167

1.3611

1.537

2.3624

15 in 12

1.250

1.5625

1.601

2.5632

16 in 12

1.333

1.7778

1.667

2.7789

17 in 12

1.417

2.0069

1.734

3.0068

18 in 12

1.500

2.25

1.803

3.2508

19 in 12

1.583

2.5069

1.875

3.5156

20 in 12

1.667

2.7778

1.948

3.7947

21 in 12

1.750

3.0625

2.010

4.0401

22 in 12

1.833

3.3611

2.083

4.3389

23 in 12

1.917

3.6736

2.167

4.6959


Running the linear regression calculation with (z, t) we get:


a = 1.000120031

b = 1.00008392

r^2 = 0.9999332927

More accurate that the quadratic regression.


z = 1.000120031 * t + 1.00008392

y^2 = 1.000120031 * x^2 + 1.00008392

y = √(1.000120031 * x^2 + 1.00008392)



Analysis


I suspect that the exact formula for the rafter factor is:

rafter factor = √( pitch^2 + 1 ), pitch as a decimal


And the roof area is:

roof area = length * width * √( pitch^2 + 1 ) [ in inches ]


Roof area in square feet = Roof area in square inches / 144



Example


Area: length = 18 feet 6 inches, width = 20 feet, pitch = 7/12

In inches, length = 222 inches, width = 240 inches


roof area = 222 * 240 * √((7/12)^2 + 1) ≈ 61682.45131 in^2 ≈ 428.3503 ft^2



Sources


Prince, Christopher DeWALT Construction Math Quick Check: Extreme Duty Edition. Delmar, Cengage Learning: Cliffon Park, NY. 2010


Elliot. “Roof Area Calculator * Surface Area Multiplied by Pitch”. sktechandcalc.com. October 20, 2017. https://www.calculator.net/roofing-calculator.html?acarea=176&acareaunit=feet&roofpitch=4&angle=25&eaves=0&eavesunit=feet&price=&priceunit=feet&ctype=pitch&tp=ar&x=Calculate


calculator.net. “Roofing Calculator” 2008 – 2024. Retrieved November 4, 2024. https://www.calculator.net/roofing-calculator.html?acarea=176&acareaunit=feet&roofpitch=4&angle=25&eaves=0&eavesunit=feet&price=&priceunit=feet&ctype=pitch&tp=ar&x=Calculate



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.


-

Casio fx-CG100: The getkey command in Python

Casio fx-CG100: The getkey command in Python The getkey command: A Demonstration The fx-CG100 adds a command to its Casioplot module,...