Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
Vankka

[OpenSecurity] Making keypad lock

Question

So i'm trying to make a "password" for a door with the keypad from OpenSecurity

 

For more info about the Keypad: https://github.com/PC-Logix/OpenSecurity/wiki/Blocks#events-1

 

The code i got before getting stuck

local event = require("event")
local component = require("component")

keypad = component.os_keypad
keypad.setEventName("eventName")
keypad.setDisplay("DoorCode")

customButtons = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "X", "0", ">"}
keypad.setKey(customButtons, customButtonColor)

--local event, address, button, button_label = event.pull("keypad")           -- I'm stuck here

while true do
if keypad == "1" then
print("1")
 if keypad == "2" then
 print("2")
  if keypad == "1" then
  print("3")
   if keypad == "1" then
    print("4")
	print("Password correct!")
elseif keypad == "1" then
print("not 1")
end
 elseif keypad == "2" then
 print("not 2")
 end
  elseif keypad == "3" then
  print("not 3")
  end
   elseif keypad == "4" then
   print("not 4")
   end
end
Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0
  • Solution

Try this. It works :-)

local accessCode = "12345"

local component = require("component")
local gpu = component.gpu
local event = require("event")
local ser = require("serialization")
local term = require("term")
local computer = component.computer
local door = component.os_door
keypad = component.os_keypad

customButtons = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "<", "0", "ok"}
customButtonColor = {"1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"}
keypad.setKey(customButtons, customButtonColor)

term.clear()
print("Security door")
print("---------------------------------------------------------------------------")

local inputStr = ""
while true do
  ev, address, button, button_label = event.pull("keypad")
  if ev then
    if button_label == "ok" then
      if inputStr == accessCode then
	term.write("Access granted\n")
	inputStr = "wellcome"
	keypad.setDisplay(inputStr)
	computer.beep()
	door.toggle()
	os.sleep(2)
	door.toggle()
      else
	term.write("Access denied\n")
	inputStr = "ERROR"
	keypad.setDisplay(inputStr)
	os.sleep(2)
      end
      inputStr = ""
    elseif button_label == "<" then
      if string.len(inputStr) > 0 then
	tmpStr = string.sub(inputStr, 1 , string.len(inputStr) -1)
	inputStr = tmpStr
      end
    else
      inputStr = inputStr .. button_label
    end
    keypad.setDisplay(inputStr)
  end
  os.sleep(0)
end

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.