Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local correctPin = "596711"
- local monitorSide = "back"
- local doorTime = 2
- function display()
- local mon = peripheral.wrap(monitorSide)
- mon.clear()
- mon.setTextScale(1)
- local xSize,ySize = mon.getSize()
- mon.setCursorPos(1,1)
- mon.write(("-"):rep( xSize ))
- local hSpace = (" "):rep( (xSize / 3) - 1 )
- local row3="|7"..hSpace.."8"..hSpace.."9|"
- local row2="|4"..hSpace.."5"..hSpace.."6|"
- local row1="|1"..hSpace.."2"..hSpace.."3|"
- mon.setCursorPos(1,2)
- mon.write(row1)
- mon.setCursorPos(1,3)
- mon.write(row2)
- mon.setCursorPos(1,4)
- mon.write(row3)
- mon.setCursorPos(1,5)
- mon.write(("-"):rep( xSize ))
- end
- function detect()
- local buttons =
- {
- [7]={2,4},
- [8]={4,4},
- [9]={6,4},
- [4]={2,3},
- [5]={4,3},
- [6]={6,3},
- [1]={2,2},
- [2]={4,2},
- [3]={6,2}
- }
- local pin = ""
- while true do
- local button
- local _,__,x,y = os.pullEvent("monitor_touch")
- for i,v in ipairs(buttons) do
- if ( x==v[1] or x==v[1]-1 ) and y==v[2] then
- button = i
- break
- end
- end
- if button then
- pin = pin .. button
- local mon = peripheral.wrap(monitorSide)
- mon.setCursorPos(#pin+1,1)
- mon.write("#")
- end
- if #pin == #correctPin then break end
- end
- local mon = peripheral.wrap(monitorSide)
- if pin == correctPin then
- mon.setBackgroundColor(colors.green)
- mon.clear()
- rs.setOutput("top",true)
- os.sleep(doorTime)
- rs.setOutput("top",false)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- else
- mon.setBackgroundColor(colors.red)
- mon.clear()
- os.sleep(0.5)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- end
- end
- while true do
- display()
- detect()
- end
Advertisement
Add Comment
Please, Sign In to add comment