This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Steiny's profile picture

Colored keypad door lock

Started by Steiny, 24 February 2015 - 09:02 AM
Steiny #1
Posted 24 February 2015 - 10:02 AM
Been learning to program and made a simple color keypad door lock.



Code can be located here: http://pastebin.com/qyfPStWt

Or type

pastebin get qyfPStWt keypad/program

Requires a small setup to use.
  • Monitor must be placed on the back of the computer.
  • You must create a file named code (poor name choice I know) and put the code you want to use in it.
  • Your code may be 1-7 characters long.
  • The code has to be in numbers: Red = 1; Green = 2; Blue = 3; Orange = 4; Yellow = 5; Purple = 6
  • The redstone output is set to the bottom, you may want to change it or adjust your setup accordingly.


Tried for hours to get a way to break the program to work, but it kept breaking. Would also like to allow the monitor to be placed on any side of the computer without breaking the program. Feedback with tips/advice and improvements for this program would be much appreciated. I will try to fix some stuff and keep the code updated.
Enjoy.
Creator #2
Posted 24 February 2015 - 04:32 PM
try somethig like


function getModemSide()
local sides = {}
sides = rs.getSides()
local side = {}
for i,v in pairs(sides) do
if peripheral.isPresent(v) == true and peripheral.getType(v) == "monitor" then
side = v
end
end
debugPrint("Got modem side")
if #side == 0 then return nil end
end

mon = peripheral.wrap(side)

Edited on 24 February 2015 - 03:46 PM
Dog #3
Posted 24 February 2015 - 05:06 PM
You'll want to use the Peripheral API for finding your monitor.

If you're using CC 1.6 or newer you can find a monitor on any side of the computer (and even attached via network cable) with…

local monitor = peripheral.find("monitor")

If you're using CC 1.58 or older you can do this for directly attached monitors…

local monitor
for _, side in pairs(rs.getSides()) do
  if peripheral.isPresent(side) and peripheral.getType(side) == "monitor" then
  monitor = peripheral.wrap(side)
  break
end

EDIT: fixed a typo
Edited on 24 February 2015 - 04:11 PM