Advertisement
Guest User

startup

a guest
Apr 17th, 2015
518
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.76 KB | None | 0 0
  1. shell.run("bg")
  2. term.clear()
  3. --button.clearTable()
  4. shell.run("monitor","monitor_0","clear")
  5. term.clear()
  6. os.loadAPI("button")
  7. term.setCursorPos(1,1)
  8. m = peripheral.wrap("monitor_0")
  9. m.clear()
  10. num1 = -1
  11. num2 = -1
  12. misc = " "
  13.  
  14. function fillTable()
  15.   button.setTable("1",one,1,3,1,3)
  16.   button.setTable("2",two,5,7,1,3)
  17.   button.setTable("3",three,9,11,1,3)
  18.   button.setTable("4",four,1,3,5,7)
  19.   button.setTable("5",five,5,7,5,7)
  20.   button.setTable("6",six,9,11,5,7)
  21.   button.setTable("7",seven,1,3,9,11)
  22.   button.setTable("8",eight,5,7,9,11)
  23.   button.setTable("9",nine,9,11,9,11)
  24.   button.setTable("0",zero,13,15,9,11)
  25.   button.setTable("/",divide,13,15,1,3)
  26.   button.setTable("*",multiply,13,15,5,7)
  27.   button.setTable("+",add,17,19,1,3)
  28.   button.setTable("-",subtract,17,19,5,7)
  29.   button.setTable("=",calc,17,19,9,11)
  30.   button.setTable("Ans",ans,21,25,1,3)
  31.   button.setTable("^",power,21,23,5,7)
  32.   button.setTable("C",clear,21,23,9,11)
  33.   button.setTable(" ",none,1000,1000,1000,1000)
  34.   button.screen()
  35. end
  36.  
  37. function getClick()
  38.   event,side,x,y = os.pullEvent("monitor_touch")
  39.   button.checkxy(x,y)
  40. end
  41.  
  42. function one()
  43.   button.flash("1")
  44.   if misc == " " then
  45.     if num1 == -1 then
  46.       num1 = 1
  47.     else
  48.       num1 = num1 * 10
  49.       sleep(0.1)
  50.       num1 = num1 + 1
  51.     end
  52.   else
  53.     if num2 == -1 then
  54.       num2 = 1
  55.     else
  56.       num2 = num2 * 10
  57.       sleep(0.1)
  58.       num2 = num2 + 1
  59.     end
  60.   end
  61. end
  62.  
  63. function two()
  64.   button.flash("2")
  65.   if misc == " " then
  66.     if num1 == -1 then
  67.       num1 = 2
  68.     else
  69.       num1 = num1 * 10
  70.       sleep(0.1)
  71.       num1 = num1 + 2
  72.     end
  73.   else
  74.     if num2 == -1 then
  75.       num2 = 2
  76.     else
  77.       num2 = num2 * 10
  78.       sleep(0.1)
  79.       num2 = num2 + 2
  80.     end
  81.   end
  82. end
  83.  
  84. function three()
  85.   button.flash("3")
  86.   if misc == " " then
  87.     if num1 == -1 then
  88.       num1 = 3
  89.     else
  90.     num1 = num1 * 10
  91.     sleep(0.1)
  92.     num1 = num1 + 3
  93.     end
  94.   else
  95.     if num2 == -1 then
  96.       num2 = 3
  97.     else
  98.       num2 = num2 * 10
  99.       sleep(0.1)
  100.       num2 = num2 + 3
  101.     end
  102.   end
  103. end  
  104.  
  105. function four()
  106.   button.flash("4")
  107.   if misc == " " then
  108.     if num1 == -1 then
  109.       num1 = 4
  110.     else
  111.     num1 = num1 * 10
  112.     sleep(0.1)
  113.     num1 = num1 + 4
  114.     end
  115.   else
  116.     if num2 == -1 then
  117.       num2 = 4
  118.     else
  119.       num2 = num2 * 10
  120.       sleep(0.1)
  121.       num2 = num2 + 4
  122.     end
  123.   end
  124. end  
  125.  
  126. function five()
  127.   button.flash("5")
  128.   if misc == " " then
  129.     if num1 == -1 then
  130.       num1 = 5
  131.     else
  132.     num1 = num1 * 10
  133.     sleep(0.1)
  134.     num1 = num1 + 5
  135.     end
  136.   else
  137.     if num2 == -1 then
  138.       num2 = 5
  139.     else
  140.       num2 = num2 * 10
  141.       sleep(0.1)
  142.       num2 = num2 + 5
  143.     end
  144.   end
  145. end  
  146.  
  147. function six()
  148.   button.flash("6")
  149.   if misc == " " then
  150.     if num1 == -1 then
  151.       num1 = 6
  152.     else
  153.     num1 = num1 * 10
  154.     sleep(0.1)
  155.     num1 = num1 + 6
  156.     end
  157.   else
  158.     if num2 == -1 then
  159.       num2 = 6
  160.     else
  161.       num2 = num2 * 10
  162.       sleep(0.1)
  163.       num2 = num2 + 6
  164.     end
  165.   end
  166. end  
  167.  
  168. function seven()
  169.   button.flash("7")
  170.   if misc == " " then
  171.     if num1 == -1 then
  172.       num1 = 7
  173.     else
  174.     num1 = num1 * 10
  175.     sleep(0.1)
  176.     num1 = num1 + 7
  177.     end
  178.   else
  179.     if num2 == -1 then
  180.       num2 = 7
  181.     else
  182.       num2 = num2 * 10
  183.       sleep(0.1)
  184.       num2 = num2 + 7
  185.     end
  186.   end
  187. end  
  188.  
  189. function eight()
  190.   button.flash("8")
  191.   if misc == " " then
  192.     if num1 == -1 then
  193.       num1 = 8
  194.     else
  195.     num1 = num1 * 10
  196.     sleep(0.1)
  197.     num1 = num1 + 8
  198.     end
  199.   else
  200.     if num2 == -1 then
  201.       num2 = 8
  202.     else
  203.       num2 = num2 * 10
  204.       sleep(0.1)
  205.       num2 = num2 + 8
  206.     end
  207.   end
  208. end  
  209.  
  210. function nine()
  211.   button.flash("9")
  212.   if misc == " " then
  213.     if num1 == -1 then
  214.       num1 = 9
  215.     else
  216.     num1 = num1 * 10
  217.     sleep(0.1)
  218.     num1 = num1 + 9
  219.     end
  220.   else
  221.     if num2 == -1 then
  222.       num2 = 9
  223.     else
  224.       num2 = num2 * 10
  225.       sleep(0.1)
  226.       num2 = num2 + 9
  227.     end
  228.   end
  229. end  
  230.  
  231. function zero()
  232.   button.flash("0")
  233.   if misc == " " then
  234.     if num1 == -1 then
  235.       num1 = 0
  236.     else
  237.     num1 = num1 * 10
  238.     sleep(0.1)
  239.     num1 = num1 + 0
  240.     end
  241.   else
  242.     if num2 == -1 then
  243.       num2 = 0
  244.     else
  245.       num2 = num2 * 10
  246.       sleep(0.1)
  247.       num2 = num2 + 0
  248.     end
  249.   end
  250. end  
  251.  
  252.  
  253.  
  254. function add()
  255.   if misc == " " then
  256.     button.toggleButton("+")
  257.     misc = "+"
  258.   elseif misc == "+" then
  259.     button.toggleButton("+")
  260.     misc = " "
  261.   else
  262.     button.toggleButton("+")
  263.     button.toggleButton(misc)
  264.     misc = "+"
  265.   end
  266. end
  267.  
  268. function subtract()
  269.   if misc == " " then
  270.     button.toggleButton("-")
  271.     misc = "-"
  272.   elseif misc == "-" then
  273.     button.toggleButton("-")
  274.     misc = " "
  275.   else
  276.     button.toggleButton("-")
  277.     button.toggleButton(misc)
  278.     misc = "-"
  279.   end
  280. end
  281.  
  282. function divide()
  283.   if misc == " " then
  284.     button.toggleButton("/")
  285.     misc = "/"
  286.   elseif misc == "/" then
  287.     button.toggleButton("/")
  288.     misc = " "
  289.   else
  290.     button.toggleButton("/")
  291.     button.toggleButton(misc)
  292.     misc = "/"
  293.   end
  294. end
  295.  
  296. function multiply()
  297.   if misc == " " then
  298.     button.toggleButton("*")
  299.     misc = "*"
  300.   elseif misc == "*" then
  301.     button.toggleButton("*")
  302.     misc = " "
  303.   else
  304.     button.toggleButton("*")
  305.     button.toggleButton(misc)
  306.     misc = "*"
  307.   end
  308. end
  309.  
  310. function power()
  311.   if misc == " " then
  312.     button.toggleButton("^")
  313.     misc = "^"
  314.   elseif misc == "^" then
  315.     button.toggleButton("^")
  316.     misc = " "
  317.   else
  318.     button.toggleButton("^")
  319.     button.toggleButton(misc)
  320.     misc = "^"
  321.   end
  322. end
  323.  
  324. function none()
  325.  
  326. end
  327.  
  328. function calc()
  329.   button.toggleButton(misc)
  330.   button.flash("=")
  331.   if misc == " " then
  332.     print("Invalid.")
  333.     m.setCursorPos(27,9)
  334.     m.write("Invalid.")
  335.   else
  336.     if misc == "/" then
  337.       ans = math.abs(num1/num2)
  338.     elseif misc == "*" then
  339.       ans = math.abs(num1*num2)
  340.     elseif misc == "+" then
  341.       ans = math.abs(num1+num2)
  342.     elseif misc == "-" then
  343.       ans = math.abs(num1-num2)
  344.     else
  345.       ans = math.abs(num1^num2)
  346.     end
  347.  m.setCursorPos(27,9)
  348.  m.write(ans)
  349.   end
  350. misc = " "
  351. sleep(0.5)
  352. end
  353.  
  354. function clear()
  355.   button.flash("C")
  356.   shell.run("reboot")
  357. end  
  358.  
  359. function ans()
  360.   if misc == " " then
  361.     num1 = ans
  362.   else
  363.     num2 = ans
  364.   end
  365. end  
  366. fillTable()
  367. button.heading("")
  368. button.label(1,1,"")
  369. ans = " "
  370. --m.setCursorPos(24,1)
  371.  
  372. while true do
  373.   getClick()
  374.   term.clear()
  375.   term.setCursorPos(1,1)
  376.   print(num1)
  377.   print(misc)
  378.   print(num2)
  379.   print("=")
  380.   print(ans)
  381.   m.setCursorPos(27,1)
  382.   m.write(num1)
  383.   m.setCursorPos(27,3)
  384.   m.write(misc)
  385.   m.setCursorPos(27,5)
  386.   m.write(num2)
  387.   m.setCursorPos(27,7)
  388.   m.write("=")
  389.   --m.setCursorPos(27,9)
  390.   --m.write(ans)
  391. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement