# First Ruby program by Steve DeRose, sderose*acm.org. # Written 3/8/03, last updated 5/13/03. # I hereby place this program in the public domain. # Calculates resistor values for Radio Shack Lm371 adjustable voltage regulator, # and write out the result as an XHTML table. # Vout = 1.25 * ( 1 + r2/r1 ) # Vout/1.25 = 1 + r2/r1 # (Vout/1.25) - 1 = r2/r1 # ((Vout/1.25) - 1) * r1 = r2 # a is the list of output voltages to be calculated for a = [ 1.25, 1.5, 2.5, 3, 4.5, 5, 6, 7.2, 7.5, 9, 10, 12, 14, 14.4, 16, 20, 24, 28, 32, 36, 40, 44, 48 ] # r1 and rr2 are two values for r1, for which the respective r2 values are calculated r1 = 240 rr1 = 220 puts "
Voltage out | " puts "r2 w/ r1 = " << r1.to_s << "ohms | "
puts "r2 w/ r1 = " << rr1.to_s << "ohms | "
puts "
---|---|---|
" << a[i].to_s << " | " << r2.to_s s = s << " | " << rr2.to_s << " |