Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ##################################
- -- password door with touch panel
- -- (using h2touchpanel API, http://pastebin.com/eK9BW600)
- -- version 0.1a
- -- http://hevohevo.hatenablog.com/
- os.loadAPI("h2touchpanel")
- -- config parameter
- local sideDoor = "right"
- local sideMon = "top"
- local pass = "12345"
- -- ############### functions
- local tmp = ""
- local success_flag = false
- function addStr(s)
- tmp = tmp..tostring(s)
- print('current: ',tmp)
- end
- function clearStr()
- tmp = ""
- print('current: ',tmp)
- end
- function certStr()
- if tmp == pass then
- success_flag =true
- print('ok! opened the door.')
- else
- success_flag =false
- print('bad! Please retry!')
- end
- tmp = ""
- end
- -- ############### button_config_table: "name" and "cmd" are required.
- local bCfg = {}
- bCfg[1]={name="1", cmd=function() addStr(1) end}
- bCfg[2]={name="2", cmd=function() addStr(2) end}
- bCfg[3]={name="3", cmd=function() addStr(3) end}
- bCfg[4]={name="4", cmd=function() addStr(4) end}
- bCfg[5]={name="5", cmd=function() addStr(5) end}
- bCfg[6]={name="6", cmd=function() addStr(6) end}
- bCfg[7]={name="7", cmd=function() addStr(7) end}
- bCfg[8]={name="8", cmd=function() addStr(8) end}
- bCfg[9]={name="9", cmd=function() addStr(9) end}
- bCfg[10]={name="0", cmd=function() addStr(0) end}
- bCfg[11]={name="clr", cmd=clearStr}
- bCfg[12]={name="enter", cmd=certStr}
- -- ############### main
- local mon = peripheral.wrap(sideMon)
- local opt = {topPos=2, bottomPos=9}
- local p1 = h2touchpanel.makePanel(bCfg, 3, 4, mon, opt)
- p1:draw()
- while true do
- tmp = ""
- success_flag = false
- term.clear()
- term.setCursorPos(1,1)
- rs.setOutput(sideDoor, false)
- print("Input password.")
- repeat
- local event, b1 = p1:pullButtonPushEvent() -- b1 is the pushed button
- b1:run() -- run the function of the pushed button.
- p1:drawPushedButtonEffect(b1, 0.5) -- pushed button b1 is highlighted for 0.5sec.
- until success_flag
- rs.setOutput(sideDoor, true)
- sleep(5)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement