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

Testing Redstone Pulse Width

Started by Yurameki, 10 July 2012 - 03:27 PM
Yurameki #1
Posted 10 July 2012 - 05:27 PM
Ok, pretty simple issue I think. I know how to fire something when a bundled input lights up or check to see if it's on. But I want to come up with a CPU efficient and accurate way to measure a redstone pulse in ticks when it comes in. Was hoping someone could provide some guidance or if I should just be using tiny sleep increments and check to see if the input is still on each tick? Thanks!
Lyqyd #2
Posted 10 July 2012 - 06:46 PM
I don't know what the resolution of os.clock is, but if it is fine enough, you could keep track of the start and end times of the pulse.

What is this for?
Yurameki #3
Posted 10 July 2012 - 07:22 PM
I'm working on a pretty complicated inventorying system taking a lot of different inputs from different devices. Working first with redstone tubes to try to get it functional. Basically I need the computer watching bundles on 3 sides and counting accurate pulses which may vary in width.
Lyqyd #4
Posted 11 July 2012 - 06:20 AM
If all you need is to count pulses (and don't care about the width), you'd be better off just using os.pullEvent() to wait for a redstone change to occur, then handling it appropriately.
Yurameki #5
Posted 11 July 2012 - 06:27 AM
I may need to figure out widths to recognize different signal types…not sure that's why I'm looking into how to do it in case I need to.

That said, if I set event handles for state changes and when it changes immediately register another event for a state change I should in theory never miss it turning off so I know to start watching for the same pulse, right?