Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("button")
- m = peripheral.wrap ("top")
- m.clear()
- function centerText(text)
- w, h = m.getSize()
- m.setCursorPos(math.floor(w/2-#text/2+.5), h/2+.5)
- m.write(text)
- m.scroll(1)
- end
- m.setCursorBlink(false)
- centerText("Hello World!")
- os.sleep(.15)
- m.clear()
- button.heading("Calculatron 9000")
- m.setCursorBlink(true)
- usenmst1 = true
- cng = 1
- cng2 = 1
- numset2= {}
- numset1= {}
- for i = 1,100 do
- numset1[i] = ""
- numset2[i] = ""
- end
- oppcanhap = false
- shouldclear = false
- function numPad()
- button.setTable("C",clear,12,15,22,24)
- button.setTable("1", one, 2,5,10,12)
- button.setTable("2", two, 7,10,10,12)
- button.setTable("3", three, 12,15,10,12)
- button.setTable("4", four, 2,5,14,16)
- button.setTable("5", five, 7,10,14,16)
- button.setTable("6", six, 12,15,14,16)
- button.setTable("7", seven, 2,5,18,20)
- button.setTable("8", eight, 7,10,18,20)
- button.setTable("9", nine, 12,15,18,20)
- button.setTable("0", zero, 7,10,22,24)
- button.setTable("+", add, 17,20,10,12)
- button.setTable("-", sub, 17,20,14,16)
- button.setTable("*", multi, 17,20,18,20)
- button.setTable("/",div,17,20,22,24)
- button.setTable("=",equal,2,5,22,24)
- button.setTable("exit", exit, 25,29,22,24)
- button.setTable("crash", crash , 24,29,18,20)
- button.screen()
- end
- function getClick()
- event,side,x,y=os.pullEvent("monitor_touch")
- button.checkxy(x,y)
- end
- function clear()
- button.flash("C")
- clearline()
- end
- function clearline()
- oppcanhap=false
- usenmst1= true
- shouldclear=false
- i = 0
- for i = 0,30 do
- i= i+1
- m.setCursorPos(i,5)
- m.write(" ")
- cng = 1
- end
- for i = 1,100 do
- numset1[i]=""
- numset2[i]=""
- end
- m.setCursorPos(4,5)
- cng = 1
- cng2 = 1
- end
- function emptyLine()
- for i = 0,30 do
- i = i+1
- m.setCursorPos(i,5)
- m.write(" ")
- cng = 1
- cng2 = 1
- end
- end
- function exit()
- button.toggleButton("exit")
- os.reboot()
- end
- function setNum(nm)
- button.flash(nm)
- if shouldclear==true then
- clearline()
- end
- if usenmst1 == true then
- numset1[cng] =nm
- m.setCursorPos(5+cng,5)
- cng = cng+1
- print(usenmst1)
- m.write(nm)
- oppcanhap=true
- elseif usenmst1==false then
- numset2[cng2]=nm
- m.setCursorPos(5+cng2,5)
- cng2=cng2+1
- print(usenmst1)
- m.write(nm)
- end
- end
- function one()
- setNum("1")
- end
- function two()
- setNum("2")
- end
- function three()
- setNum("3")
- end
- function four()
- setNum("4")
- end
- function five()
- setNum("5")
- end
- function six()
- setNum("6")
- end
- function seven()
- setNum("7")
- end
- function eight()
- setNum("8")
- end
- function nine()
- setNum("9")
- end
- function zero()
- setNum("10")
- end
- function equal()
- button.flash("=")
- if opptype == "add" then
- nst2 = table.concat(numset2)
- nst1 = table.concat(numset1)
- opt = nst1 + nst2
- printOut(opt)
- print(nst1)
- print(nst2)
- elseif opptype == "subtract" then
- nst2 = table.concat(numset2)
- nst1 = table.concat(numset1)
- opt = nst1-nst2
- printOut(opt)
- elseif opptype == "multiply" then
- nst2 = table.concat(numset2)
- nst1 = table.concat(numset1)
- opt = nst1*nst2
- printOut(opt)
- elseif opptype == "divide" then
- nst2 = table.concat(numset2)
- nst1 = table.concat(numset1)
- opt = nst1/nst1
- printOut(opt)
- else
- clearLine()
- print(Err)
- sleep(2)
- clearLine()
- end
- shouldclear=true
- end
- function printOut(opt)
- clearline()
- m.write(opt)
- end
- function add()
- if oppcanhap == true then
- button.flash("+")
- opptype = "add"
- usenmst1=false
- emptyLine()
- end
- end
- function sub()
- if oppcanhap==true then
- button.flash("-")
- opptype = "subtract"
- usenmst1=false
- emptyLine()
- end
- end
- function multi()
- if oppcanhap==true then
- button.flash("*")
- opptype="multiply"
- usenmst1=false
- emptyLine()
- end
- end
- function div()
- if oppcanhap==true then
- button.flash("/")
- opptype="divide"
- usenmst1= false
- emptyLine()
- end
- end
- numPad()
- m.setCursorPos(5,5)
- while true do
- getClick()
- end
Advertisement
Add Comment
Please, Sign In to add comment