Alyce
Nov 15, 2011
**Science Programming in Liberty BASIC** Welcome to the Liberty Basic Science Programming Page. I hope this page will offer interested parties many ideas, solutions, and interesting LB programming code that will enrich your teaching/learning experience in the field of science. I have been a science teacher for longer than I wish to admit. I still enjoy the learning, however, and especially love writing programs in Liberty Basic that help me to get the point across, or sometimes, help me manage my classroom. I would like to get things off to a good start by posting some code to a program I just finished today involving the spectral lines produced by quantum electron transitions.The program calculates wavelengths of the Balmer lines of the hydrogen spectrum and shows the lines as they would appear in a spectroscope. Please feel free to use this and any other programs you find here.Now I can't take credit for all of this code- the Liberty Basic Forum folks were invaluable in helping me over the rough spots, especially with the second program that gives students practice in measuring with a metric ruler. I recommend a visit over there to learn a great deal from experienced people.[[Spectral Lines]] Also- don't be shy about posting you own code or maybe a program you have been thinking about writing. This is a place for sharing information and ideas.--Scott[[code]] '********************************************************** 'This program uses the Rydberg modification of the Balmer 'formula to calculate the wavelength of light produced when 'an electron returns to energy level 2 from one of 5 higher 'energy levels. It also simulates the color of the light in the 'hydrogen spectrum produced when this transition occurs.'*********************************************************** 'Window set ups ''*********************************************************** nomainwin---- You may edit this page by clicking the button at the top labeled "Edit This Page". Or CLICK HERE.WindowWidth = 640 WindowHeight = 660 UpperLeftX = int((DisplayWidth-WindowWidth)/2) UpperLeftY = int((DisplayHeight-WindowHeight)/2)The editor for the wiki is similar to Wordpad. The toolbar at the top has buttons for formatting, adding links and files, and to preview or save the modifications.graphicbox #w.g, 10, 10, 600, 500 statictext #w.s, "Enter principle quantum # 3-7 in**New pages can be added by creating a link on this page, or by selecting "New Page" from thebox then click 'Save' ", 10, 600, 550, 30 textbox #w.tb1, 10, 520, 200, 32 textbox #w.tb2, 20,100,300,32 textbox #w.tb3, 20,150,300,32 textbox #w.tb4, 20,200,300,32main navigation pane at the upper left corner of the wiki.** You can choose to use the "Science" template to get started, or you can start from a blank page.button #w.b1, "Save", [entered], LR, 300, 40, 60, 30 open "Hydrogen Emission Spectra" for window as #w #w, "trapclose [quit]" #w.tb1 "!font arial 16 bold" #w.s "!font arial 12" #w.tb1 "!setfocus"When you visit your new page, you can add code by using code tags. Here is a sample.'***************************************************** 'Draw wavelength ruler and make marks '*****************************************************`` code [[code]] code goes here code `` [[code]]#w.g, "goto 50 400" #w.g, "down" #w.g, "goto 50 450" #w.g, "goto 550 450" #w.g, "goto 550 400" #w.g, "flush" #w.g, "goto 50 400" x = 50 y = 400 z = 425 #w.g, "up" #w.g, "goto ";x;" ";z forfor i = 1 to9 x = x + 50 #w.g, "goto ";x;" ";y #w.g, "down" #w.g, "goto ";x;" ";z #w.g, "up" next10 print ix = 50 y = 400 z = 410 #w.g, "up" #w.g, "goto ";x;" ";z for i = 1 to 100 x = x + 5 #w.g, "goto ";x;" ";y #w.g, "down" #w.g, "goto ";x;" ";z #w.g, "up" next i x = 50 y = 400 z = 425 for j = 1 to 19 x = x + 25 #w.g, "goto ";x;" ";y #w.g, "down" #w.g, "goto ";x;" ";z #w.g, "up" next j '************************************************** 'print the wavelengths in nm '************************************************** x = 95 y = 430 d = 300 #w.g,"down" #w.g, "place ";x;" ";y print #w.g, "\";d for j = 1 to 8 d = d+50 x = x + 50 #w.g, "place ";x;" ";y print #w.g, "\";d next j #w.g, "flush" #w.g, "up" #w.g, "goto 50 400" #w.g, "down" x = 550:y = 350 print #w.g, "backcolor white" print #w.g, "color white" print #w.g, "boxfilled ";x;" ";y #w.g, "goto 50 400" #w.g, "down" x = 550 print #w.g, "backcolor black" print #w.g, "box ";x;" ";y print #w.g, "boxfilled ";x;" ";y print #w.g,"flush" wait '************************************************** 'Show emission line in response to wavelength entry '************************************************** [entered] #w.tb1 "!contents? reply$" n =val( reply$) '**************************************************** 'calculation '**************************************************** c = (1/4)-(1/n^2) L = 1/(1.097e7 *c) i = 9 rounded = int(L*10^i +0.5) / 10^i wavelength = rounded * 1e9 print #w.tb2, "1.097e7 * [1/2^2 - 1/";n^2;"] = 1/lambda" print #w.tb3, "lambda = 1/(1.907e7 * ";c;")" print #w.tb4, "wavelength = ";wavelength;" nm" select case wavelength case 656 #w.g,"up" #w.g,"color red" #w.g,"backcolor red" #w.g, "size 5" #w.g,"goto 457 355"'355 use for all #w.g,"down" #w.g,"goto 457 394"'394 use for all #w.g,"flush" wait case 486 #w.g,"up" #w.g,"color cyan" #w.g,"backcolor cyan" #w.g, "size 5" #w.g,"goto 286 355"'355 use for all #w.g,"down" #w.g,"goto 286 394"'394 use for all #w.g,"flush" wait case 434 #w.g,"up" #w.g,"color 130 100 215" #w.g,"backcolor 130 100 215" #w.g, "size 5" #w.g,"goto 235 355"'355 use for all #w.g,"down" #w.g,"goto 235 394"'394 use for all #w.g,"flush" wait case 410 #w.g,"up" #w.g,"color 110 10 180" #w.g,"backcolor 110 10 180" #w.g, "size 5" #w.g,"goto 210 355"'355 use for all #w.g,"down" #w.g,"goto 210 394"'394 use for all #w.g,"flush" wait case 397 #w.g,"up" #w.g,"color 70 0 120" #w.g,"backcolor 70 0 120" #w.g, "size 5" #w.g,"goto 200 355"'355 use for all #w.g,"down" #w.g,"goto 200 394"'394 use for all #w.g,"flush" wait case else wait end select wait [quit] close #w end [[code]]next