Showing posts with label horsepower. Show all posts
Showing posts with label horsepower. Show all posts

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.


Sunday, December 3, 2023

Casio fx-5000F: Auto Formulas

Casio fx-5000F:   Auto Formulas



The formula listing can apply to (almost) any calculator that can handle formula programming.


In November, there I want to a luncheon that a local car club had in Riverside.  Of course, this was an opportunity to bring a calculator and find something in common with the members.   I previously did this with a TI-68.


Except noted, US, imperial units are used.  


The source for all the equations are from The Auto Math Handbook, except for Gas Efficiency.  




Stroke of an Engine

(spaces added for readability)


S = D / ( π / 4 × B^2 × n ) = D / ( π / 4 × B² × n )


S = stroke (in)

D = displacement (in^3)

B = bore (in)

n = number of cylinders


Example:

D = 421

B = 4 

n = 6


Result: 

S ≈ 5.58369 in 



Engine Horsepower


H = R × T × 2 × π / 33000


H = engine horsepower (hp)

R = revolutions per minute (rpm)

T = torque (lbs-ft)


Example:

R = 5200 

T = 446


Result:

H ≈441.57465



Theoretical Air Capacity of an Engine


C = R × D / 3456


C = air capacity (in^3/min [cubic feet per minute])

R = revolutions per minute (rpm)

D = displacement (in^3)


Example:

R = 5200

D = 421 


Result:

C ≈ 633.44907



Estimated Elapsed Time in a Quarter Mile


The time is based off an engine's weight (really, mass) and horsepower.


E = 5.825 × ³√( W / H ) = 5.825 × ( W / H )^(1/3)


E = elapsed time in seconds (sec)

W = weight of the automobile/truck (pounds)

H = horsepower of the engine (hp)


Example:

W = 3676 

H = 440


Result:

E ≈ 11.81962



Gear Ratio 


This estimates the final gear ratio.  Note that 63360 ÷ 60 = 1056, allowing a simplified formula to be used.


G = R × T × θ / M / 1056


G = gear ratio

R = revolutions per minute (rpm)

T = tire diameter (in)

M = miles per hour (mph) (average)


Example:

R = 5200

T = 28

M = 57.8


Result:

G ≈ 7.49410



Tire Diameter


T = W × A / 1270 + R


Take the following measurements as they are marked on the tire:


[LT/P]  W / A  [R/B]   R


W = section width (mm:  yes, somehow U.S. tires measure this in millimeters)

A = aspect ratio (percentage difference between section height and section width)

R = rim diameter (in)


T = tire diameter (in)


Example:

W = 235

A = 75

R = 15


Result:

D ≈ 28.87795



Gas Efficiency


M = (B - A) / g


B = ending mileage (mi)

A = beginning mileage (mi)

g = number of gallons used


M = gas efficiency (mpg, miles per gallon)


Example:

B = 13695

A = 13385

G = 10


Result:

M = 31



Source


Lawlor, John.   Auto Math Handbook:  Calculations, Formulas, Equations and Theory  HPBooks  New York, NY 1992.



Eddie


All original content copyright, © 2011-2023.  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. 


Sunday, April 30, 2023

TI-74 and Python (Casio fx-9750GIII): A Treasure of Programs

TI-74 and Python (Casio fx-9750GIII):  A Treasure of Programs



Today's programs illustrates an approach from both the BASIC and Python programming languages. 



Skiing Stars



This program paves a ski path by randomly plotting a path.  A slight difference:  the TI-74 version goes indefinitely until the user presses a key and uses one line.  The Python version goes 50 steps and the result must be scrolled up after the program completes.  I optimized the program to fit each screen.


TI-74 BASICALC Program


100 REM "Skiing Stars"

102 RANDOMIZE RND

104 P=14

106 PRINT "Press any key to stop.": PAUSE .25

120 CALL KEY(K,S)

122 IF S<>0 THEN 140

124 R=RND

126 IF R<.4 AND P>0 THEN LET P=P-1

128 IF R>.4 AND P<26 THEN LET P=P+1

130 DISPLAY ERASE ALL AT(P),"*****": PAUSE .15

132 GOTO 120

140 PRINT RPT$("*",31): PAUSE .25

142 STOP


Python (Casio fx-9750GIII):  skistar.py


# skiing stars

from random import *

rnd=int(10000000*random())

seed(rnd)

p=8

for i in range(50):

  r=random()

  if r<.4 and p>0:

    p-=1

  if r>.6 and p<14:

    p+=1

  print(" "*p+"*****")

print("scroll up")

    


Phase Speed of a Wave


Equation:

c = √( g  * λ / (2 * π) * tanh(2 * π * d / λ))


c = phase speed

λ = wavelength 

d = water depth

g = Earth's gravity = 9.80665 m/s = 32.174049 ft/s


Source:


"Wind Wave"  Wikipedia.  Last Edited January 28, 2023.  Accessed February 14, 2023.  https://en.wikipedia.org/wiki/Wind_wave#:~:text=In%20fluid%20dynamics%2C%20a%20wind,is%20known%20as%20the%20fetch.


TI-74 BASICALC Program:  


400 REM Phase Speed

402 PRINT "U.S. units used": PAUSE .25

404 T=2*PI: G=32.174049

406 INPUT "Depth (ft)? "; D

408 INPUT "Wavelength (ft)? "; L

410 C=SQR(G*L/T*TANH(T*D/L))

412 PRINT "Phase Speed (ft/s)=": PAUSE .25

414 PRINT C: PAUSE

416 STOP


Python (Casio fx-9750GIII): phspeed.py  


# phase speed

from math import *

print("U.S  units used")

t=2*pi

g=32.174049

print("Depth (ft)?")

d=float(input())

print("Wavelength?")

l=float(input())

c=sqrt(g*l/t*tanh(t*d/l))

print("Phase speed (ft/s)=")

print(c)


Example:


Depth:  2.26 ft

Wavelength:  18.9 ft


Result:  

Phase Speed:  7.845145563 ft/s



Horsepower Generated by a Wave


p = 0.0329 * h^2 * √( l * (1 - 4.935 * (h^2/l^2))


h = wave height (ft)

l = length of a wave (ft)

p = horsepower


Source: 


Rosenstein, Morton.  Strategies for Scientific Calculating Casio.  January 1982.


TI-74 BASICALC Program:


500 REM horsepower of a wave

502 PRINT "U.S. units used": PAUSE .25

504 INPUT "Wave height (ft)? ";H

506 INPUT "Length of wave (ft)? "; L

508 P=.0329*H^2*SQR(L*(1-4.935*(H^2/L^2)))

510 PRINT "Horsepower = ": PAUSE .25

512 PRINT P: PAUSE

514 STOP


Python (Casio fx-9750GIII):  hpwave.py


# horsepower of a wave

from math import *

print("U.S. units used")

print("Wave height (ft)?")

h=float(input())

print("Length of a wave?")

l=float(input())

p=.0329*h**2*sqrt(l*(1-4.935*(h**2/l**2)))

print("horsepower = ")

print(p)


Example:


Wave height:  1.26 ft

Length of wave: 24.04 ft


Result:

Horsepower = .2543549811 hp



Until next time,


Eddie



All original content copyright, © 2011-2023.  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. 


RPN HP 12C: Fibonacci and Lucas Sequences

  RPN HP 12C: Fibonacci and Lucas Sequences Golden Ratio, Formulas, and Sequences Let φ be the Golden Ratio: φ = (1 + √5) ÷ 2...