Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
praryboy

Using bundled cables quickly

Question

I am building a simple microcontroller to use as a sort of toggle latch. The idea is I'll have multiple buttons connected to different colored wires connected to the input, and pressing one will set that color to ON on the output until the user presses a different button.

 

The problem is the redstone_changed event doesn't pass back which color initiated the event, and in the time it takes for a For loop to iterate through the colors and find the one that is currently ON, it has already turned OFF again (minecraft buttons only issue a pulse for a moment). Is there any way to get the color that initiated the redstone_changed event or a way to get a snapshot of the current input of all colors that I can then iterate through, or any other solution?

Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0

I am using a Tier 2 card. The problem is not that I can't get the value of the color cable. The problem is that the color is not returned by the redstone_changed event, so you have to loop through all the colors calling getBundledInput() on each looking for the one that changed. If the change was initiated by a normal wooden button on the white channel, for example, unless the code is fast enough, there is a good chance the button has turned off already by the time the code gets to checking the white cable.

 

What I've managed to do since posting the question is create a loop that quickly calls getBundledInput() on all the colors and puts it in a table, which I can then use the slower loop to search through. It works 90% of the time, so it will do for now.

 

I doubt this is the right place to post this, but I'd really like for the redstone_changed event to return the color as well as the value, or failing that a function in the redstone api that returns a table with the values of all the colors at once. Otherwise many systems that only give short pulses over redstone essentially can't be monitored effectively, as the pulse would be long over by the time the computer can react to it. 

Link to post
Share on other sites
  • 0

 

 

Otherwise many systems that only give short pulses over redstone essentially can't be monitored effectively, as the pulse would be long over by the time the computer can react to it. 

I see your point. And your solution is simlilar to what i would have proposed which would be something like a coroutine constantly scanning the state of each colored wire along with an event listener. When the redstone_changed event fires the coroutine could queue its own redstone event with the parameters you desire. just a thought.

Link to post
Share on other sites
  • 0

I have a solution that may require you to test personally but so far it will catch any wire change i throw at it regardless of pulse length..

local event = require "event"
local computer = require "computer"
local colors = require "colors"
local sides = require "sides"
local rs = require('component').redstone
local e

local bundle = (function() -- init bundle with states
  local bundle = {}
  for side = 0, 5 do
    bundle[side] = {}
    for color = 0, 15 do
      bundle[side][color] = rs.getBundledInput(side, color)
    end
  end
  return bundle
end)()

local handler = {
  redstone_changed = function(e)
    local side, state = e[3], nil
    for color = 0, 15 do
      state = rs.getBundledInput(side, color)
      if state ~= bundle[side][color] then
        bundle[side][color] = state
        computer.pushSignal('wire_changed', e[2], sides[side], colors[color], state)
      end
    end
  end,
  wire_changed = function(e)
    print(e[1],e[2],e[3],e[4],e[5])
  end
}

while true do
  e = {event.pull()}
  if handler[e[1]] then handler[e[1]](e) end
end

hope this helps.

Link to post
Share on other sites
  • 0

This forum is very helpful, thank you very much for your responses.

 

In case you didn't notice (because maybe I check github too much), there's now a way to get all the bundled redstone values at once: just don't pass in a color to the getBunldedInput (or getBundledOutput) method. https://github.com/MightyPirates/OpenComputers/commit/ffd38e59ff373e63a204314475de829383523b56

Authored 3 days ago

Awesome, I was just about to update OC anyway.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.