Advertisement
Mackan90096

Keypad

Mar 29th, 2015
573
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. m = peripheral.wrap("monitor_41")
  2. cIn = ""
  3. code = "0000"
  4. side = "back"
  5.  
  6. function setup()
  7.   redstone.setOutput(side, true)
  8.   m.setBackgroundColor(32768)
  9.   m.clear()
  10.   m.setCursorPos(1,1)
  11.   m.write("1")
  12.   m.setCursorPos(3, 1)
  13.   m.write("2")
  14.   m.setCursorPos(5, 1)
  15.   m.write("3")
  16.   m.setCursorPos(1, 3)
  17.   m.write("4")
  18.   m.setCursorPos(3, 3)
  19.   m.write("5")
  20.   m.setCursorPos(5, 3)
  21.   m.write("6")
  22.   m.setCursorPos(1, 5)
  23.   m.write("7")
  24.   m.setCursorPos(3, 5)
  25.   m.write("8")
  26.   m.setCursorPos(5, 5)
  27.   m.write("9")
  28.   m.setCursorPos(7, 1)
  29.   m.setBackgroundColor(32)
  30.   m.write("O")
  31.   m.setBackgroundColor(16384)
  32.   m.setCursorPos(7, 5)
  33.   m.write("X")
  34.   m.setBackgroundColor(32768)
  35.   m.setCursorPos(7, 3)
  36.   m.write("0")
  37. end
  38.  
  39. setup()
  40.  
  41. function checkCode()
  42.   if(cIn == code) then
  43.     redstone.setOutput(side, false)
  44.     sleep(3)
  45.     redstone.setOutput(side, true)
  46.     cIn = ""
  47.   else
  48.     cIn = ""
  49.   end
  50. end
  51.  
  52. while true do
  53.   _, p1, p2, p3 = os.pullEvent("monitor_touch")
  54.   if(p1 == "monitor_41") then
  55.     if(p2 == 1 and  p3 == 1) then
  56.        cIn = cIn.."1"
  57.     elseif(p2 == 3 and p3 == 1) then
  58.       cIn = cIn.."2"
  59.     elseif(p2 == 5 and p3 == 1) then
  60.       cIn = cIn.."3"
  61.     elseif(p2 == 1 and p3 == 3) then
  62.       cIn = cIn.."4"
  63.     elseif(p2 == 3 and p3 == 3) then
  64.       cIn = cIn.."5"
  65.     elseif(p2 == 5 and p3 == 3) then
  66.       cIn = cIn.."6"
  67.     elseif(p2 == 1 and p3 == 5) then
  68.       cIn = cIn.."7"
  69.     elseif(p2 == 3 and p3 == 5) then
  70.       cIn = cIn.."8"
  71.     elseif(p2 == 5 and p3 == 5) then
  72.       cIn = cIn.."9"
  73.     elseif(p2 == 7 and p3 == 3) then
  74.       cIn = cIn.."0"
  75.     elseif(p2 == 7 and p3 == 1) then
  76.       checkCode()
  77.     elseif(p2 == 7 and p3 == 5) then
  78.       cIn = ""
  79.    
  80.     end  
  81.   end
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement