Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shell.run("bg")
- term.clear()
- --button.clearTable()
- shell.run("monitor","monitor_0","clear")
- term.clear()
- os.loadAPI("button")
- term.setCursorPos(1,1)
- m = peripheral.wrap("monitor_0")
- m.clear()
- num1 = -1
- num2 = -1
- misc = " "
- function fillTable()
- button.setTable("1",one,1,3,1,3)
- button.setTable("2",two,5,7,1,3)
- button.setTable("3",three,9,11,1,3)
- button.setTable("4",four,1,3,5,7)
- button.setTable("5",five,5,7,5,7)
- button.setTable("6",six,9,11,5,7)
- button.setTable("7",seven,1,3,9,11)
- button.setTable("8",eight,5,7,9,11)
- button.setTable("9",nine,9,11,9,11)
- button.setTable("0",zero,13,15,9,11)
- button.setTable("/",divide,13,15,1,3)
- button.setTable("*",multiply,13,15,5,7)
- button.setTable("+",add,17,19,1,3)
- button.setTable("-",subtract,17,19,5,7)
- button.setTable("=",calc,17,19,9,11)
- button.setTable("Ans",ans,21,25,1,3)
- button.setTable("^",power,21,23,5,7)
- button.setTable("C",clear,21,23,9,11)
- button.setTable(" ",none,1000,1000,1000,1000)
- button.screen()
- end
- function getClick()
- event,side,x,y = os.pullEvent("monitor_touch")
- button.checkxy(x,y)
- end
- function one()
- button.flash("1")
- if misc == " " then
- if num1 == -1 then
- num1 = 1
- else
- num1 = num1 * 10
- sleep(0.1)
- num1 = num1 + 1
- end
- else
- if num2 == -1 then
- num2 = 1
- else
- num2 = num2 * 10
- sleep(0.1)
- num2 = num2 + 1
- end
- end
- end
- function two()
- button.flash("2")
- if misc == " " then
- if num1 == -1 then
- num1 = 2
- else
- num1 = num1 * 10
- sleep(0.1)
- num1 = num1 + 2
- end
- else
- if num2 == -1 then
- num2 = 2
- else
- num2 = num2 * 10
- sleep(0.1)
- num2 = num2 + 2
- end
- end
- end
- function three()
- button.flash("3")
- if misc == " " then
- if num1 == -1 then
- num1 = 3
- else
- num1 = num1 * 10
- sleep(0.1)
- num1 = num1 + 3
- end
- else
- if num2 == -1 then
- num2 = 3
- else
- num2 = num2 * 10
- sleep(0.1)
- num2 = num2 + 3
- end
- end
- end
- function four()
- button.flash("4")
- if misc == " " then
- if num1 == -1 then
- num1 = 4
- else
- num1 = num1 * 10
- sleep(0.1)
- num1 = num1 + 4
- end
- else
- if num2 == -1 then
- num2 = 4
- else
- num2 = num2 * 10
- sleep(0.1)
- num2 = num2 + 4
- end
- end
- end
- function five()
- button.flash("5")
- if misc == " " then
- if num1 == -1 then
- num1 = 5
- else
- num1 = num1 * 10
- sleep(0.1)
- num1 = num1 + 5
- end
- else
- if num2 == -1 then
- num2 = 5
- else
- num2 = num2 * 10
- sleep(0.1)
- num2 = num2 + 5
- end
- end
- end
- function six()
- button.flash("6")
- if misc == " " then
- if num1 == -1 then
- num1 = 6
- else
- num1 = num1 * 10
- sleep(0.1)
- num1 = num1 + 6
- end
- else
- if num2 == -1 then
- num2 = 6
- else
- num2 = num2 * 10
- sleep(0.1)
- num2 = num2 + 6
- end
- end
- end
- function seven()
- button.flash("7")
- if misc == " " then
- if num1 == -1 then
- num1 = 7
- else
- num1 = num1 * 10
- sleep(0.1)
- num1 = num1 + 7
- end
- else
- if num2 == -1 then
- num2 = 7
- else
- num2 = num2 * 10
- sleep(0.1)
- num2 = num2 + 7
- end
- end
- end
- function eight()
- button.flash("8")
- if misc == " " then
- if num1 == -1 then
- num1 = 8
- else
- num1 = num1 * 10
- sleep(0.1)
- num1 = num1 + 8
- end
- else
- if num2 == -1 then
- num2 = 8
- else
- num2 = num2 * 10
- sleep(0.1)
- num2 = num2 + 8
- end
- end
- end
- function nine()
- button.flash("9")
- if misc == " " then
- if num1 == -1 then
- num1 = 9
- else
- num1 = num1 * 10
- sleep(0.1)
- num1 = num1 + 9
- end
- else
- if num2 == -1 then
- num2 = 9
- else
- num2 = num2 * 10
- sleep(0.1)
- num2 = num2 + 9
- end
- end
- end
- function zero()
- button.flash("0")
- if misc == " " then
- if num1 == -1 then
- num1 = 0
- else
- num1 = num1 * 10
- sleep(0.1)
- num1 = num1 + 0
- end
- else
- if num2 == -1 then
- num2 = 0
- else
- num2 = num2 * 10
- sleep(0.1)
- num2 = num2 + 0
- end
- end
- end
- function add()
- if misc == " " then
- button.toggleButton("+")
- misc = "+"
- elseif misc == "+" then
- button.toggleButton("+")
- misc = " "
- else
- button.toggleButton("+")
- button.toggleButton(misc)
- misc = "+"
- end
- end
- function subtract()
- if misc == " " then
- button.toggleButton("-")
- misc = "-"
- elseif misc == "-" then
- button.toggleButton("-")
- misc = " "
- else
- button.toggleButton("-")
- button.toggleButton(misc)
- misc = "-"
- end
- end
- function divide()
- if misc == " " then
- button.toggleButton("/")
- misc = "/"
- elseif misc == "/" then
- button.toggleButton("/")
- misc = " "
- else
- button.toggleButton("/")
- button.toggleButton(misc)
- misc = "/"
- end
- end
- function multiply()
- if misc == " " then
- button.toggleButton("*")
- misc = "*"
- elseif misc == "*" then
- button.toggleButton("*")
- misc = " "
- else
- button.toggleButton("*")
- button.toggleButton(misc)
- misc = "*"
- end
- end
- function power()
- if misc == " " then
- button.toggleButton("^")
- misc = "^"
- elseif misc == "^" then
- button.toggleButton("^")
- misc = " "
- else
- button.toggleButton("^")
- button.toggleButton(misc)
- misc = "^"
- end
- end
- function none()
- end
- function calc()
- button.toggleButton(misc)
- button.flash("=")
- if misc == " " then
- print("Invalid.")
- m.setCursorPos(27,9)
- m.write("Invalid.")
- else
- if misc == "/" then
- ans = math.abs(num1/num2)
- elseif misc == "*" then
- ans = math.abs(num1*num2)
- elseif misc == "+" then
- ans = math.abs(num1+num2)
- elseif misc == "-" then
- ans = math.abs(num1-num2)
- else
- ans = math.abs(num1^num2)
- end
- m.setCursorPos(27,9)
- m.write(ans)
- end
- misc = " "
- sleep(0.5)
- end
- function clear()
- button.flash("C")
- shell.run("reboot")
- end
- function ans()
- if misc == " " then
- num1 = ans
- else
- num2 = ans
- end
- end
- fillTable()
- button.heading("")
- button.label(1,1,"")
- ans = " "
- --m.setCursorPos(24,1)
- while true do
- getClick()
- term.clear()
- term.setCursorPos(1,1)
- print(num1)
- print(misc)
- print(num2)
- print("=")
- print(ans)
- m.setCursorPos(27,1)
- m.write(num1)
- m.setCursorPos(27,3)
- m.write(misc)
- m.setCursorPos(27,5)
- m.write(num2)
- m.setCursorPos(27,7)
- m.write("=")
- --m.setCursorPos(27,9)
- --m.write(ans)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement