- Sky
- Blueberry
- Slate
- Blackcurrant
- Watermelon
- Strawberry
- Orange
- Banana
- Apple
- Emerald
- Chocolate
- Charcoal
deace_nuts
-
Content Count
10 -
Joined
-
Last visited
Posts posted by deace_nuts
-
-
I've got a door control that I'd like one computer to run on startup, is there anyway of doing this?
-
I've got a door control that I'd like one computer to run on startup, is there anyway of doing this?
-
18 hours ago, Molinko said:
I'm sorry for the headache rather than the help..
local component = require("component") local sides = require("sides") local event = require("event") local term = require("term") local thread = require("thread") local rs = component.redstone local gpu = component.gpu -- Config local delay, isOpen = 5, (rs.getOutput(sides.right) > 0) and true or false local timer = nil term.clear() term.setCursor(1, 1) gpu.setForeground(0x00FF00) print("--------------------------- ToNELvision MICROSYTEMS ---------------------------\n") gpu.setForeground(0xFFFFFF) print("Welcome. Please enter one of the displayed commands. It may take a few seconds for the command to be interpreted.\n") gpu.setForeground(0xE6AB38) print("Open\nClose") term.setCursor(1, 9) local inputThread inputThread = thread.create(function() while true do local input = term.read(nil, false) if type(input) == "string" then input = input:sub(1, -2) elseif type(input) == "boolean" and input == false then print("interrupted") inputThread:kill() end term.clearLine() if input == "open" or input == "Open" then if not isOpen then rs.setOutput(sides.right, 15) isOpen = true if timer then event.cancel(timer) end timer = event.timer(delay, function() if isOpen then rs.setOutput(sides.right, 0) isOpen = false timer = nil end end) end elseif input == "close" or input == "Close" then if isOpen then rs.setOutput(sides.right, 0) event.cancel(timer) isOpen = false end elseif input == "quit" or input == "Quit" then inputThread:kill() end end end) local motionThread = thread.create(function() while true do local _, _, x, y, name = event.pull("motion") if not isOpen then rs.setOutput(sides.right, 15) isOpen = true if timer then event.cancel(timer) end timer = event.timer(delay, function() if isOpen then rs.setOutput(sides.right, 0) isOpen = false timer = nil end end) else event.cancel(timer) timer = event.timer(delay, function() if isOpen then rs.setOutput(sides.right, 0) isOpen = false timer = nil end end) end end end) thread.waitForAny({inputThread, motionThread}) print("\nProgram Exit") os.exit()
Tested... sorry for the headache...
That works fantastic, thank you!
-
27 minutes ago, Molinko said:
I edited the original script in my post. I'm confident I fixed open() however I'm not sure if threads can call thread:kill() from within themselves.. So quitting may still be bugged :/
Open and quit still don't do anything.
-
1 hour ago, Molinko said:
The thread library is included in later versions of openos. Check the forums for openos updater. Download it with internet card. Install it. Lemme know how it goes.
I see, I've noticed that the motion sensor works, but neither Open nor Quit does anything.
-
6 hours ago, Molinko said:
local component = require("component") local sides = require("sides") local event = require("event") local term = require("term") local thread = require("thread") local rs = component.redstone local gpu = component.gpu -- Config local delay = 5 local function open() rs.setOutput(side.right, 15) os.sleep(delay) rs.setOutput(side.right, 0) end local inputThread inputThread = thread.create(function() while true do term.clear() term.setCursor(1, 1) gpu.setForeground(0x00FF00) print("--------------------------- ToNELvision MICROSYTEMS ---------------------------\n") gpu.setForeground(0xFFFFFF) print("Welcome. Please enter one of the displayed commands. It may take a few seconds for the command to be interpreted.\n") gpu.setForeground(0xE6AB38) print("Open\nClose") term.setCursor(1, 9) local input = term.read() if input == "open" or input == "Open" then open() end if input == "quit" or input == "Quit" then inputThread:kill() end end end) local motionThread = thread.create(function() while true do local _, _, x, y, name = event.pull("motion") open() end end) thread.waitForAny({inputThread, motionThread}) print("\nProgram Exit")
This is and example using payonels thread api. I haven't used it yet myself but it is very powerful. Hats off to payonel for this one.
If this example has a bug, (its untested), lets me know the error and ill try to remedy it..
Wow, thank you so much for doing this! Though it looks like for some reason it can't find the thread library, is that a non-included library?
-
8 hours ago, Gorzoid said:
io.read() is a blocking call, you either need to remove that input or use one of the coroutine APIs like threads to run both at the "same" time.
I replaced io.read() with event.pull() and now the motion sensor works perfectly. Though now I can't enter anything to open the door, so clearly I used the wrong call, right?
-
45 minutes ago, Molinko said:
The motion sensor must be in line of sight. Solid blocks and maybe even doors will keep the motion sensor from triggering. From a glance the code seems like it should work as expected...
hmm, then maybe the sensitivity is too low? How can I change that?The sensitivity is fine actually. I don't know what's up with it. I ran it as it's own script and it worked (mind you it didn't keep a solid redstone output, so the piston kept moving.) so maybe it has something to do with how I structured it. Is it my "While true do"?
-
I have this script that I wrote to control a piston door via redstone and on the other side of the door I have a motion sensor to open the piston door (toggle the redstone signal on). For some reason the motion sensor isn't doing anything, though. I know it's something I did, I'm new to LUA.
local component = require("component") local sides = require("sides") local event = require("event") local gpu = component.gpu local term = require("term") local rs = component.redstone -- Config local delay = 5 while true do -- GUI term.clear() gpu.setForeground(0x00FF00) print("--------------------------- ToNELvision MICROSYTEMS ---------------------------\n") gpu.setForeground(0xFFFFFF) print("Welcome. Please enter one of the displayed commands. It may take a few seconds for the command to be interpreted.\n") gpu.setForeground(0xE6AB38) print("Open") print("Close") gpu.setForeground(0xFFFFFF) term.setCursor(1,9) local input=io.read() if input == "Open" then rs.setOutput(side.right, 15) os.sleep(delay) rs.setOutput(side.right, 0) else wrong = true end -- Motion Sensor local id, _, x, y, entityName = event.pull("motion") rs.setOutput(sides.right, 15) os.sleep(delay) rs.setOutput(sides.right, 0) end
Can I autorun a program?
in Programming
Posted
So if my program is named door.lua and it's located in /home, I would do...
Edit /etc/rc.d -> enabled = {} -> enabled = {"door.lua"}
Is that correct? If so it's not working, so I must have done something wrong.