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

Need help with a timed redstone signal

Started by Wookie, 16 April 2013 - 04:27 AM
Wookie #1
Posted 16 April 2013 - 06:27 AM
Hi, i was looking over the forum but unable to find exactly what i was looking for, i was however able to find a good timer that i can use but i have not been able to add a signal to it at timed intervals. what im trying to do is send out a signal every 5 mins that lasts for around a min. My script atm is:


mon = peripheral.wrap("right") –connects to the monitor on top of the computer
sec = 0 –declare variables
min = 0
uur = 0

mon.setTextScale(1.5) –set the text scale of the monitor to a 1.5 magnification

term.redirect(mon) –redirect the output ot the monitors
while true do –main loop
term.clear() –clear the screen
term.setCursorPos(1,1) –set the cursor to the left upper corner

if sec==60 then –if 60 seconds have past add 1 to minutes and set seconds to 0
min = min + 1 –adds 1 to minutes
sec = 0
end –ends if

sec = sec + 1 –counts the seconds

if min==60 then –if 60 minutes have past add 1 to uur(hours) and set minutes to 0
uur = uur + 1 –adds 1 to uur(hours)
min = 0

end
–prints everything
print("time is: ")
print(sec.." seconds")
print(min.." minutes")
print(uur.." hours")
sleep(1) –sleeps for 1 second
end
Bubba #2
Posted 16 April 2013 - 06:30 AM

while true do --Will loop forever
  rs.setOutput("<side>", true) --Set the redstone output to the specified side to true
  sleep(60) -- wait 60 seconds
  rs.setOutput("<side>", false) --Set it to false
  sleep(60*5) -- sleep for 5 minutes
end

That's all you need in terms of timer code.

Just add in the monitor code and you're good to go.
Wookie #3
Posted 16 April 2013 - 06:32 AM
Thanks
Wookie #4
Posted 16 April 2013 - 07:23 AM

while true do --Will loop forever
  rs.setOutput("<side>", true) --Set the redstone output to the specified side to true
  sleep(60) -- wait 60 seconds
  rs.setOutput("<side>", false) --Set it to false
  sleep(60*5) -- sleep for 5 minutes
end

That's all you need in terms of timer code.

Just add in the monitor code and you're good to go.

How do i make this go on forever do i copy and paste it loads of times or can i edit it to run for ever?
Bubba #5
Posted 16 April 2013 - 07:34 AM
It will go on forever. That's what the while true do does. Hence the reason for my comment "will loop forever" ;)/>
Wookie #6
Posted 16 April 2013 - 08:10 AM
hmm maybe i need to test it again as its stoped when i tried, i didnt add the monitor code maybe thats why it stops?
Bubba #7
Posted 16 April 2013 - 09:17 AM
hmm maybe i need to test it again as its stoped when i tried, i didnt add the monitor code maybe thats why it stops?

Does it display an error or does it just finish with the usual "> " character?
Wookie #8
Posted 16 April 2013 - 10:27 PM
No error displayed it just seems to end after, can any1 add a counter to the code for me so i can see if im just missing it or if it is stoping?