Cavious

keypad

Jun 6th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.43 KB | None | 0 0
  1. --[[
  2. startup.lua(keypad.lua)
  3. Created By Cavious(Donald R. Valverde)
  4. Version 0.5-ALPHA
  5.  
  6. SETUP REQUIREMENTS
  7. ==================
  8. (1)One Gold COMPUTER
  9. (2)One Gold Monitor
  10. ]]--
  11.  
  12. --[[
  13. UPDATES COMING TO THIS FILE
  14. ===========================
  15. (1)RedNet Controls(SEND, RECEIVE)
  16. (2)Secure variables
  17. (3)Security log(TextFile with ComputerCraft Database Connection)
  18. ]]--
  19.  
  20. --##################VARIABLES##################
  21. mon_side = "" --The side your monitor is on.
  22. door_side = ""
  23. definedTime = 1 --Enter delay for door open & close; DEFAULT = 1
  24.  
  25. --YOUR PASSWORD HERE
  26. --Consists of three, one digit codes, all must be numerical.
  27. password_code1 = "" --Enter 1 digit into the "".
  28. password_code2 = "" --Enter 1 digit into the "".
  29. password_code3 = "" --Enter 1 digit into the "".
  30.  
  31.  
  32. --###############DO NOT TOUCH##################
  33. --DO NOT TOUCH THIS VARIABLE!
  34. mon = peripheral.wrap(mon_side) --SIDE SET BY YOU ABOVE
  35. code = {} -- USED BY THE COMPUTER ONLY!
  36. curNum = 1 --DEFAULT DO NOT TOUCH
  37. --##############################################
  38.  
  39. --#################FUNCTIONS####################
  40. function run()
  41.     initialize()
  42.     main()
  43. end
  44.  
  45. function initialize()
  46.     mon.clear()
  47.     mon.setTextScale(1)
  48.    
  49.     drawBackground()
  50.     displayText()
  51. end
  52.  
  53. function drawBackground()
  54.     term.redirect(mon)
  55.     background = paintutils.loadImage(".background")
  56.     paintutils.drawImage(background, 1, 1)
  57.     term.native()
  58. end
  59.  
  60. function displayText()
  61.     --Set Number on Pad
  62.  
  63.     --Send Buttons
  64.     mon.setTextColor(colors.black)
  65.     mon.setBackgroundColor(colors.yellow)
  66.  
  67.     --Left Send Button
  68.     mon.setCursorPos(2,2)
  69.     mon.write("S")
  70.     mon.setCursorPos(2,3)
  71.     mon.write("E")
  72.     mon.setCursorPos(2,4)
  73.     mon.write("N")
  74.     mon.setCursorPos(2,5)
  75.     mon.write("D")
  76.  
  77.     --Right Send Button
  78.     mon.setCursorPos(6,2)
  79.     mon.write("S")
  80.     mon.setCursorPos(6,3)
  81.     mon.write("E")
  82.     mon.setCursorPos(6,4)
  83.     mon.write("N")
  84.     mon.setCursorPos(6,5)
  85.     mon.write("D")
  86.  
  87.     --Number Buttons
  88.     mon.setTextColor(colors.white)
  89.  
  90.     --Green Numbers
  91.     mon.setBackgroundColor(colors.green)
  92.     mon.setCursorPos(3,3)
  93.     mon.write("1")
  94.     mon.setCursorPos(5,3)
  95.     mon.write("3")
  96.     mon.setCursorPos(4,4)
  97.     mon.write("5")
  98.     mon.setCursorPos(3,5)
  99.     mon.write("7")
  100.     mon.setCursorPos(5,5)
  101.     mon.write("9")
  102.  
  103.     --Lime Numbers
  104.     mon.setBackgroundColor(colors.lime)
  105.     mon.setCursorPos(4,3)
  106.     mon.write("2")
  107.     mon.setCursorPos(3,4)
  108.     mon.write("4")
  109.     mon.setCursorPos(5,4)
  110.     mon.write("6")
  111.     mon.setCursorPos(4,5)
  112.     mon.write("8")
  113. end
  114.  
  115. function buttonCheck(xPos, yPos)
  116.      --SEND BUTTON CHECK
  117.      if(xPos == 2 and yPos >= 2 or xPos == 6 and yPos >= 2 and yPos <= 5) then
  118.         if (pass.num1 == password_code1 and pass.num2 == password_code2 and pass.num3 == password_code3) then
  119.        
  120.         --########FOR TESTING ONLY########
  121.         mon.setCursorPos(1,1)
  122.         mon.setBackgroundColor(colors.white)
  123.         mon.write(" ")
  124.         --################################
  125.        
  126.         --RESET ALL VARIABLES, KEYS, AND PAD
  127.         --OPEN AND CLOSE DOOR
  128.         curNum = 1 --Reset the entry back to the first number of the password.
  129.        
  130.         redstone.setOutput(door_side, true)
  131.         os.sleep(definedTime)
  132.         redstone.setOutput(door_side, false)
  133.        
  134.         mon.setBackgroundColor(colors.black)
  135.        
  136.         mon.setCursorPos(3,2)
  137.         mon.write(" ")
  138.        
  139.         mon.setCursorPos(4,2)
  140.         mon.write(" ")
  141.        
  142.         mon.setCursorPos(5,2)
  143.         mon.write(" ")
  144.        
  145.         end
  146.       end
  147.      
  148.     --1 BUTTON CHECK
  149.     if(xPos == 3 and yPos == 3) then
  150.         if curNum == 1 then
  151.          
  152.             --Save Number to variable
  153.             pass.num1 = "1"
  154.          
  155.             --Display on Dial pad
  156.             mon.setCursorPos(3,2)
  157.             mon.setTextColor(colors.white)
  158.             mon.setBackgroundColor(colors.black)
  159.             mon.write("*")
  160.            
  161.             --Add one to the curNum
  162.             curNum = curNum + 1
  163.             os.sleep(0.5)
  164.         end
  165.        
  166.         if curNum == 2 then
  167.          
  168.             --Save Number to variable
  169.             pass.num2 = "1"
  170.          
  171.             --Display on Dial pad
  172.             mon.setCursorPos(4,2)
  173.             mon.setTextColor(colors.white)
  174.             mon.setBackgroundColor(colors.black)
  175.             mon.write("*")
  176.            
  177.             --Add one to the curNum
  178.             curNum = curNum + 1
  179.         end
  180.        
  181.         if curNum == 3 then
  182.          
  183.             --Save Number to variable
  184.             pass.num3 = "1"
  185.          
  186.             --Display on Dial pad
  187.             mon.setCursorPos(5,2)
  188.             mon.setTextColor(colors.white)
  189.             mon.setBackgroundColor(colors.black)
  190.             mon.write("*")
  191.            
  192.             --Add one to the curNum
  193.             curNum = curNum + 1
  194.         end
  195.     end
  196.    
  197.     --2 BUTTON CHECK
  198.     if(xPos == 4 and yPos == 3) then
  199.         if curNum == 1 then
  200.          
  201.             --Save Number to variable
  202.             pass.num1 = "2"
  203.          
  204.             --Display on Dial pad
  205.             mon.setCursorPos(3,2)
  206.             mon.setTextColor(colors.white)
  207.             mon.setBackgroundColor(colors.black)
  208.             mon.write("*")
  209.            
  210.             --Add one to the curNum
  211.             curNum = curNum + 1
  212.         end
  213.        
  214.         if curNum == 2 then
  215.          
  216.             --Save Number to variable
  217.             pass.num2 = "2"
  218.          
  219.             --Display on Dial pad
  220.             mon.setCursorPos(4,2)
  221.             mon.setTextColor(colors.white)
  222.             mon.setBackgroundColor(colors.black)
  223.             mon.write("*")
  224.            
  225.             --Add one to the curNum
  226.             curNum = curNum + 1
  227.         end
  228.        
  229.         if curNum == 3 then
  230.          
  231.             --Save Number to variable
  232.             pass.num3 = "2"
  233.          
  234.             --Display on Dial pad
  235.             mon.setCursorPos(5,2)
  236.             mon.setTextColor(colors.white)
  237.             mon.setBackgroundColor(colors.black)
  238.             mon.write("*")
  239.            
  240.             --Add one to the curNum
  241.             curNum = curNum + 1
  242.         end
  243.        
  244.         mon.setCursorPos(1,1)
  245.         mon.setTextColor(colors.white)
  246.         mon.write(curNum)
  247.     end
  248. end
  249.  
  250. function main()
  251.  
  252.     while(true) do
  253.         event, side, xPos, yPos = os.pullEvent("monitor_touch")
  254.         buttonCheck(xPos, yPos)
  255.     end
  256. end
  257.  
  258. --####################MAIN########################
  259. run()
Advertisement
Add Comment
Please, Sign In to add comment