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

Red Pulse With Persistance

Started by campicus, 20 September 2013 - 01:10 AM
campicus #1
Posted 20 September 2013 - 03:10 AM
Hello all,

thought I would post this little program I put together. Basically, I use computers instead of timers to pulse machines. This program allows me to set up a computer as a pulser, which will survive server restarts, etc.

Feedback would be great as this is the first program I have posted!
Spoiler

local tArgs = {...}
local program = shell.getRunningProgram()
os.setComputerLabel("pulser")
if fs.exists("pulseLog") then
  h = fs.open("pulseLog", "r")
  log = textutils.unserialize(h.readAll())
  h.close()
  sSide = log[1]
  duration = log[2]
  sInterval = tonumber(duration)/2
else
  if not tArgs[1] then
	print("Set parameters: <side> <pulse interval>")
	return
  end
  sSide = tArgs[1]
  duration = tArgs[2]
  sInterval = tonumber(duration)/2
  h = fs.open("pulseLog", "w")
  h.write(textutils.serialize(tArgs))
  h.close()
  h = fs.open("startup", "w")
  h.write("shell.run(\""..program.."\")")
  h.close()
end
while true do
  term.clear()
  term.setCursorPos(1,1)
  print("Pulsing "..sSide.." every "..duration.." seconds.")
  rs.setOutput(sSide, true)
  sleep(sInterval)
  rs.setOutput(sSide, false)
  sleep(sInterval)
end

http://pastebin.com/T0STJ1UM
hex450 #2
Posted 20 September 2013 - 06:14 AM
I use


while true do
rs.setOutput("side",true)
sleep(0.1)
rs.setOutput("side",false)
sleep(1)
end

Save it as startup and it will also survive server restarts &amp; all of that annoying stuff, not as fancy but it works.
campicus #3
Posted 20 September 2013 - 10:49 AM
-snip-

That is essentially what my program is :P/> This just makes it easier setting up multiple timers. Something that is easy to do once turns into a hassle the 100th time :P/>
campicus #4
Posted 22 September 2013 - 08:41 PM
I was really hoping for a bit of feedback on this, as it is my first program :s
frostthejack #5
Posted 23 September 2013 - 01:32 PM
does that actually work writing to startup i always get an error when trying to write to startup
campicus #6
Posted 23 September 2013 - 08:14 PM
does that actually work writing to startup i always get an error when trying to write to startup

Yep, it all works :)/> What error do you get?