SHOW:
|
|
- or go back to the newest paste.
1 | local c = require("component") | |
2 | local keypad = c.os_keypad | |
3 | local computer = require("computer") | |
4 | local event = require("event") | |
5 | ||
6 | local code = "12345678" -- Your code (Max 8 digits to fit on keypad display) | |
7 | local user_code = "" -- Variable that stores input | |
8 | ||
9 | local run = true | |
10 | while run do | |
11 | local e, address, _, key = event.pull(1000) | |
12 | if (e and e == "interrupted") then -- Kill program when ctrl + c is pressed | |
13 | run = false | |
14 | elseif (e and e == "keypad") then | |
15 | if (key and key == "*") then -- Uses star button as reset key | |
16 | user_code = "" | |
17 | keypad.setDisplay("") | |
18 | elseif (key) then -- On key other than reset key add it to user_code | |
19 | user_code = user_code .. key | |
20 | keypad.setDisplay(user_code) -- Update display to updated input string | |
21 | end | |
22 | if (string.len(code) == string.len(user_code)) then -- If code and user_code are the same length: | |
23 | if (code == user_code) then -- Test if they match | |
24 | computer.beep(2000) | |
25 | print("Code correct!") | |
26 | keypad.setDisplay("CORRECT") | |
27 | user_code = "" | |
28 | else | |
29 | computer.beep(100) | |
30 | print("Wrong code!") | |
31 | keypad.setDisplay("WRONG") | |
32 | user_code = "" | |
33 | end | |
34 | end | |
35 | - | elseif (e and e == "magData") then -- If mag card is detected, check if stored string matches code |
35 | + | |
36 | - | if (key == code) then |
36 | + |