Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --SensorDoorControl
- --initialize
- monitor = peripheral.wrap("back")
- outputSide = "bottom"
- rs.setOutput(outputSide, false)
- monitor.clear()
- monitor.setBackgroundColour(colors.black)
- --VAR
- IsOpen = false
- Password = "1234"
- CurrPass = ""
- sTextColor = colors.black
- sTxtBgColor = colors.white
- RS_SkipCounter = 0
- --draw a PINpad
- function Draw()
- monitor.clear()
- strl = string.len(CurrPass)
- --draw a PINPAD header (or inputed text)
- if (IsOpen) then
- DrawText(1,1,"OPENED", colors.green, colors.black)
- elseif (strl > 0) then
- DrawText(1,1,">", colors.white, colors.black) --CurrPass
- for i=2, strl+1, 1 do
- DrawText(i,1,"*", colors.white, colors.black)
- end
- else
- DrawText(1,1,"CLOSED", colors.red, colors.black)
- end
- --Symbols
- DrawText(3,2, "1", sTextColor, sTxtBgColor)
- DrawText(4,2, "2", sTextColor, sTxtBgColor)
- DrawText(5,2, "3", sTextColor, sTxtBgColor)
- --
- DrawText(3,3, "4", sTextColor, sTxtBgColor)
- DrawText(4,3, "5", sTextColor, sTxtBgColor)
- DrawText(5,3, "6", sTextColor, sTxtBgColor)
- --
- DrawText(3,4, "7", sTextColor, sTxtBgColor)
- DrawText(4,4, "8", sTextColor, sTxtBgColor)
- DrawText(5,4, "9", sTextColor, sTxtBgColor)
- --colors.red
- DrawText(3,5, "R", sTextColor, colors.red)
- DrawText(4,5, "0", sTextColor, sTxtBgColor)
- --colors.green
- DrawText(5,5, "E", sTextColor, colors.green)
- end
- --draw a symbol
- function DrawText(PosX, PosY, Text, TextColor, BgColor)
- monitor.setCursorPos(PosX,PosY)
- monitor.setBackgroundColor(BgColor) --colors.black
- monitor.setTextColor(TextColor) --colors.white
- monitor.write(Text)
- monitor.setTextColor(colors.black)
- monitor.setBackgroundColor(colors.black)
- end
- --Event on screen touch
- function TouchEvent(PosX, PosY)
- digit = -1
- clear = false
- apply = false
- --get touched symbol
- if (PosX == 3 and PosY == 2) then
- digit = 1
- elseif (PosX == 4 and PosY == 2) then
- digit = 2
- elseif (PosX == 5 and PosY == 2) then
- digit = 3
- elseif (PosX == 3 and PosY == 3) then
- digit = 4
- elseif (PosX == 4 and PosY == 3) then
- digit = 5
- elseif (PosX == 5 and PosY == 3) then
- digit = 6
- elseif (PosX == 3 and PosY == 4) then
- digit = 7
- elseif (PosX == 4 and PosY == 4) then
- digit = 8
- elseif (PosX == 5 and PosY == 4) then
- digit = 9
- elseif (PosX == 3 and PosY == 5) then
- clear = true
- elseif (PosX == 4 and PosY == 5) then
- digit = 0
- elseif (PosX == 5 and PosY == 5) then
- apply = true
- end
- --add symbol or process
- if (digit >= 0) then
- CurrPass = CurrPass..digit
- if (string.len(CurrPass) > 6) then
- CurrPass = ""
- end
- elseif (clear) then
- CurrPass = ""
- IsOpen = false
- elseif (apply) then
- if (CurrPass == Password) then
- IsOpen = true
- else
- CurrPass = ""
- end
- end
- --Open or close door
- rs.setOutput(outputSide, IsOpen)
- RS_SkipCounter = 0
- --redraw screen
- Draw()
- end
- --Triggered by redstone
- function RedstoneEvent()
- if (RS_SkipCounter >= 2) then
- CurrPass = ""
- IsOpen = false
- rs.setOutput(outputSide, IsOpen)
- Draw()
- RS_SkipCounter = 0
- else
- RS_SkipCounter = RS_SkipCounter + 1
- end
- end
- --Fisrt draw
- Draw()
- repeat
- event,p1,p2,p3 = os.pullEvent()
- if event=="monitor_touch" then
- --p2 -- sets mouseWidth
- --p3 -- and mouseHeight
- TouchEvent(p2, p3)
- end
- if event=="redstone" then
- RedstoneEvent()
- end
- until event=="char" and p1==("q")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement