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

Synchronize input redstone pulse to a stable pulse.

Started by Cota, 06 November 2012 - 06:48 PM
Cota #1
Posted 06 November 2012 - 07:48 PM
Im currently block on how to do this, hadn't got a lot of sandbox whit this language :P/>/>

My problem is that i have a redstone pulse that is un-synchronized, this pulse comes from processed items that come from my factory and they come around 1-4 by second so, i could really just fix this pulse mixing by using a buffer to synchronize them to a more stable pulse, but since i already have a computer to manage the whole process of the factory i want as well to use the computer to count the created items and stabilize the pulse for a "Filter" (Tekkit) that provides the same amount of items needed to create the ones that exit.

In small words, if 10 items come out on a wave of production, the computer needs to give out 10 stable pulses whit out stop reading new incoming pulses.

Problem: It cant read pulses and output at the same time (don't know if this is possible).
Kryptanyte #2
Posted 06 November 2012 - 07:51 PM
Why not use a second computer to read the count? So you have one computer that is looking for a rednet message asking for the count which if it is not finding will continue counting the items but if that second computer asks for the count it will send its current item count, so the other computer can pulse as many times as you want.

Its really up to you though. Personally I think that it would be easier with 2 computers rather than one.
Cota #3
Posted 06 November 2012 - 08:00 PM
I did tough that, using rednet would do all easy "send count, reset count to 0, profit", the thing is knowing if it can be done whit one, i already have to put on/off on machines so the server doesn't lags and this factory is fast on producing stuff since i use a lot of Construction Foam. I was using a Counter and a Timer to do the job, but they lag the crap whit their animations.
robhol #4
Posted 06 November 2012 - 09:05 PM
You might want to try the parallel API.
Doyle3694 #5
Posted 06 November 2012 - 09:08 PM
again no. parallel still cant double yield
Lyqyd #6
Posted 07 November 2012 - 05:00 AM
again no. parallel still cant double yield

What? Parallel is the wrong thing to use here, but not because it "cant [sic] double yield", whatever that is supposed to mean.

You'll want one loop that pulls events and uses timers to set the output pulses on a regular schedule. Adjust the timer timings as necessary.


local inSide, outSide = "left", "right"
local inState = rs.getInput(inSide)
local pulseCount = 0
local pulseTimer = os.startTimer(0.8)
local pulseOffTimer
while true do
    e, p1 = os.pullEvent()
    if e == "redstone" then
        if inState ~= rs.getInput(inSide) then
            if inState then
                pulseCount = pulseCount + 1
            end
            inState = rs.getInput(inSide)
        end
    elseif e == "timer" then
        if p1 == pulseTimer then
            if pulseCount >= 1 then
                rs.setOutput(outSide, true)
                pulseOffTimer = os.startTimer(0.4)
                pulseCount = pulseCount - 1
            end
            pulseTimer = os.startTimer(0.8)
        elseif p1 == pulseOffTimer then
            rs.setOutput(outSide, false)
        end
    end
end
Doyle3694 #7
Posted 07 November 2012 - 10:21 AM
that you cant have 2 yields at the same time
Lyqyd #8
Posted 07 November 2012 - 11:09 AM
that you cant have 2 yields at the same time

I don't think you understand Lua coroutines or how the parallel API works. I'm not even sure why you seem to think that "two yields at the same time" is even a necessary thing in this case.
Cota #9
Posted 10 November 2012 - 08:10 AM
After some "try's" on this matter it seems that computercraft cant manage this, my setup is now 2 wireless computers, one at the side of the other one, it looks sad but its the only way to avoid lagging the server whit redstone animations :<
D3matt #10
Posted 10 November 2012 - 08:13 AM
After some "try's" on this matter it seems that computercraft cant manage this, my setup is now 2 wireless computers, one at the side of the other one, it looks sad but its the only way to avoid lagging the server whit redstone animations :<
Um… Lyqyd just told you how it can be done.
Cota #11
Posted 10 November 2012 - 09:53 PM
Edit* Testing
simou2 #12
Posted 30 November 2012 - 05:54 PM
again no. parallel still cant double yield

What? Parallel is the wrong thing to use here, but not because it "cant [sic] double yield", whatever that is supposed to mean.

You'll want one loop that pulls events and uses timers to set the output pulses on a regular schedule. Adjust the timer timings as necessary.


local inSide, outSide = "left", "right"
local inState = rs.getInput(inSide)
local pulseCount = 0
local pulseTimer = os.startTimer(0.8)
local pulseOffTimer
while true do
	e, p1 = os.pullEvent()
	if e == "redstone" then
		if inState ~= rs.getInput(inSide) then
			if inState then
				pulseCount = pulseCount + 1
			end
			inState = rs.getInput(inSide)
		end
	elseif e == "timer" then
		if p1 == pulseTimer then
			if pulseCount >= 1 then
				rs.setOutput(outSide, true)
				pulseOffTimer = os.startTimer(0.4)
				pulseCount = pulseCount - 1
			end
			pulseTimer = os.startTimer(0.8)
		elseif p1 == pulseOffTimer then
			rs.setOutput(outSide, false)
		end
	end
end


i love this code but is their a way to puse the lower part of the code and then continue later

local stop = "back"

like if rs.getInput(stop) = true then
this stop the computer out puting but it makes it stil able to count the input

and then when the stop truns false be able to pules the left ove outputs it has in memory

ive been trying to work it out but have had no lack and i dont full under stand the lua code yet
Orwell #13
Posted 30 November 2012 - 06:08 PM

local inSide, outSide, stopSide = "left", "right"."back"
local inState = rs.getInput(inSide)
local stopState = rs.getInput(stopSide)
local pulseCount = 0
local pulseTimer = os.startTimer(0.8)
local pulseOffTimer
while true do
	e, p1 = os.pullEvent()
	if e == "redstone" then
		if inState ~= rs.getInput(inSide) then
			if inState then
				pulseCount = pulseCount + 1
			end
			inState = rs.getInput(inSide)
		end
	    stopState = rs.getInput(stopSide)
	elseif e == "timer" and not stopState then
		if p1 == pulseTimer then
			if pulseCount >= 1 then
				rs.setOutput(outSide, true)
				pulseOffTimer = os.startTimer(0.4)
				pulseCount = pulseCount - 1
			end
			pulseTimer = os.startTimer(0.8)
		elseif p1 == pulseOffTimer then
			rs.setOutput(outSide, false)
		end
	end
end
This should stop outputting as long as there is a redstone signal on the back. It continues when the redstone signal is off again.
simou2 #14
Posted 02 December 2012 - 04:39 PM
Thank you Orwell

that is a load esay way then the way i was trying to do it

but i had to modify it for it to get it to start up agian after stopinput code is below

and thanks agin


local inSide, outSide, stopSide = "left", "right","back"
local inState = rs.getInput(inSide)
local stopState = rs.getInput(stopSide)
local pulseCount = 0
local pulseTimer = os.startTimer(0.8)
local pulseOffTimer
while true do
	    e, p1 = os.pullEvent()
	    if e == "redstone" then
			    if inState ~= rs.getInput(inSide) then
					    if inState then
							    pulseCount = pulseCount + 1
					    end
					    inState = rs.getInput(inSide)
			    end
		    stopState = rs.getInput(stopSide)
  pulseTimer = os.startTimer(0.8)
	    elseif e == "timer" and not stopState then
			    if p1 == pulseTimer then
					    if pulseCount >= 1 then
							    rs.setOutput(outSide, true)
							    pulseOffTimer = os.startTimer(0.4)
							    pulseCount = pulseCount - 1
					    end
					    pulseTimer = os.startTimer(0.8)
			    elseif p1 == pulseOffTimer then
					    rs.setOutput(outSide, false)
			    end
	    end
end
Lyqyd #15
Posted 02 December 2012 - 05:40 PM
Here's a modified version that should work a little more cleanly, based on Orwell's code above.


local inSide, outSide, stopSide = "left", "right", "back"
local inState = rs.getInput(inSide)
local pulseCount = 0
local pulseTimer = os.startTimer(0.8)
local pulseOffTimer
while true do
e, p1 = os.pullEvent()
    if e == "redstone" then
        if inState ~= rs.getInput(inSide) then
            if inState then
                pulseCount = pulseCount + 1
            end
            inState = rs.getInput(inSide)
        end
    stopState = rs.getInput(stopSide)
    elseif e == "timer" then
        if p1 == pulseTimer then
            if pulseCount >= 1 and not rs.getInput(stopSide) then
                rs.setOutput(outSide, true)
                pulseOffTimer = os.startTimer(0.4)
                pulseCount = pulseCount - 1
            end
            pulseTimer = os.startTimer(0.8)
        elseif p1 == pulseOffTimer then
            rs.setOutput(outSide, false)
        end
    end
end
simou2 #16
Posted 02 December 2012 - 07:06 PM
thanks lyqyd

that works better i worked out that the timer was not refrsing but i see puting 'not stopstate' their make it stops outputing if it gets stopstate when it is outputing and it also make it update its timer too if the stopstate is on.

may thanks all this has help we loads im starting to under stand coding a bit more each day thanks
ChunLing #17
Posted 03 December 2012 - 03:28 AM
Maybe it would better to just toggle the redstone rather than to pulse it? That way you don't need to muck about with timers and such, you just collect redstone events and toggle the redstone output.

It should also be slightly more reliable, able to react faster to inputs.

Or, since you considered doing this using modems, perhaps use a bit of bundled cable?
Lyqyd #18
Posted 03 December 2012 - 06:34 AM
Maybe it would better to just toggle the redstone rather than to pulse it? That way you don't need to muck about with timers and such, you just collect redstone events and toggle the redstone output.

It should also be slightly more reliable, able to react faster to inputs.

Or, since you considered doing this using modems, perhaps use a bit of bundled cable?

Considering that the question revolved around outputting a steady pulse given an unpredictably-varied input, I'm not sure how you envision getting that to work using only redstone events and no timers.
ChunLing #19
Posted 03 December 2012 - 10:15 AM
I'm probably not envisioning the setup correctly. This just all seems very hit and miss. Maybe have a turtle collect all the output items and explicitly count them?