Jump to content




Start/Stop Shell.run by redstone input


3 replies to this topic

#1 Remcob

  • New Members
  • 2 posts

Posted 15 December 2012 - 12:01 AM

Hi all!

I'm new here, just started experimenting with ComputerCraft for the very first time.
I've managed to make a short ruleboard with rotating text and a small timer based program with redstone output for my bacon machine by looking at many of the helpfull tips and programs on this forum. (i dont know a thing about Lua btw)

So now im making a cinema and i want to start and stop the implented StarWars movie by use of two buttons.
The file below i want to set as startup and then be able to start and stop the movie. When stopping the movie it should return to the initial state so i can start it again at wish.
I don't think i'm on the right track here, so any help would be highly appreciated.
Thanks in advance!

monitor.clear()
monitor.setCursorPos(1,1)
while true do
  os.pullEvent('redstone')
  if redstone.getBundledInput("bottom",1) then -- waiting for pulse on white
  shell.run("monitor,"top","/secret/alongtimeago")
  end
if redstone.getBundledInput("bottom",2) then -- waiting for pulse on yellow
os.reboot()
end


#2 Goof

  • Members
  • 751 posts

Posted 15 December 2012 - 02:07 AM

you can do this over rednet...(its a bit easier)

this is the computer, which should stay behind the monitor in cinema.
local side = "front" -- edit this to the side, the monitor is on...
local running = true
local rSide = "top" --edit to Modem side.
rednet.open(rSide)

function tSave(fSave)

if fs.exists("cinema.cfg") then
fRead = fs.open("cinema.cfg", "r")
fCfg = fRead.readLine()
fRead.close()
else
fWrite = fs.open("cinema.cfg", "w")
fWrite.writeLine(fSave)
fWrite.close()
end
end
mon = peripheral.wrap(side)
function clear()
mon.clear()
tSave("false")
os.reboot()
end
function startMovie()
while running do
if fCfg == "true" then
shell.run("monitor", side, "rom/programs/secret/alongtimeago")
fCfg = "false"
end
end
end
function receive()
id, msg = rednet.receive()
if msg == "stop" then
clear()
elseif msg == "start" then
fCfg = "true"
end
end

parallel.waitForAny(receive, startMovie)


this should listen for a rednet message "stop" or "start"

then the command central computer:

local rSide = "top" -- edit to modem side
local receiveID = 1 -- edit to display computers id.
local running = true
rednet.open(rSide)

function clear()
term.clear()
term.setCursorPos(1,1)
end
while running do
clear()
print("Command \"start\" or \"stop\"")
write("command > ")
cmd = read()
if cmd == "start" then
rednet.send(receiveID, "start")
print("Message sent")
sleep(2)
elseif cmd == "stop" then
rednet.send(receiveID, "stop")
print("Message Sent")
sleep(2)
else
print("wrong input...")
sleep(2)
end
end




that should be the easy way... ( there is no buttons, but you just have to write "start" or "stop" in the computer, to start/stop the cinema :D

Hope that helps...

and ps:

i know we should not code everything for you, but i am happy today, so... yeah :D


-Mikk809h

#3 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 15 December 2012 - 02:09 AM

Stuff like this usually calls for some parallel magic! (also revised some of your script, hope you don't mind.)

shell.run('monitor', 'top', 'clear')

function waitForRS(n)
  repeat
    os.pullEvent('redstone')
  until rs.testBundledInput('bottom', n)
end

function movie()
  shell.run('monitor','top', 'secret/alongtimeago')
end

function stop()
  waitForRS(2)
end

waitForRS(1)
parallel.waitForAny(movie, stop)


#4 Remcob

  • New Members
  • 2 posts

Posted 15 December 2012 - 02:58 AM

Both thanks for the help/sollution!
The second script seems alot simpler but that first one gives me quite a few ideas for further projects...

About the second one: do i understand that it has just a single redstone input? First one starts it, second one stops it?

I'm going to try out both!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users