1. Please make sure you are posting in the correct place. Server ads go here and modpack bugs go here

Basic Redstone on off ComputerCraft code

Discussion in 'General FTB chat' started by The Snipe, Jan 2, 2014.

  1. The Snipe

    The Snipe Active Member

    Hey guys,

    I'm wodnering does anyone know where I could find, (Or could help me write up) a basic code for computercraft that turns on/off a redstone signal on a certain colour on a Rednet cable by pushing buttons on a touch screen.

    I found this code:

    http://www.computercraft.info/forum...easy-monitor-touch-screen-for-bundled-cables/

    But it uses a custom API, so I'm wondering if someone could even just help to change it so it can use the rs.setBundledOutput

    I'm looking for it to help with my Railcraft villager sorter/smelter and I'd probably end up using it to control my base from one place too.

    (I only really need it to be a simple analog on/off, I'm sure once most of it is there once, I can just copy+paste the same thing in again and again changing the colour ID's etc to change it around for different uses)

    Any help would be absolutely amazing!

    Thanks lads! :D
     
  2. Bomb Bloke

    Bomb Bloke Well-Known Member

    Sure, why not. May have a use for it myself.

    Code:
    local cableSide = "right"  -- Or where ever your cable is.
    
    local mon = peripheral.wrap("left") -- Or where ever your colour monitor is.
    mon.setTextColor(colours.white)
    mon.setBackgroundColor(colours.black)
    mon.clear()
    
    local xLen, yLen = mon.getSize()
    
    local myEvent
    
    -- Menu items.
    -- Add as desired, but don't exceed 16 entries.
    local switches = {
       ["Block Smasher"] = {colour = colours.white,  screenRow =  1},
       ["Atom Splitter"] = {colour = colours.red,  screenRow =  5},
       ["Nuke Factory"]  = {colour = colours.yellow, screenRow = 10}}
    
    -- Initial menu render:
    for key,value in pairs(switches) do
       mon.setBackgroundColor(colours.black)
       mon.setCursorPos(2,value.screenRow)
       mon.write(key)
       mon.setCursorPos(xLen-5,value.screenRow)
       
       if colours.test(rs.getBundledOutput(cableSide),value.colour) then
         mon.setBackgroundColor(colours.green)
         mon.write(" On  ")
       else
         mon.setBackgroundColor(colours.red)
         mon.write(" Off ")
       end
    end     
    
    -- Main program loop.
    while true do
       myEvent = {os.pullEvent("monitor_touch")}
       
       for key,value in pairs(switches) do if myEvent[4] == value.screenRow then
         mon.setCursorPos(xLen-5,value.screenRow)
    
         if not colours.test(rs.getBundledOutput(cableSide),value.colour) then
           mon.setBackgroundColor(colours.green)
           mon.write(" On  ")
           rs.setBundledOutput(cableSide,colours.combine(rs.getBundledOutput(cableSide),value.colour))
         else
           mon.setBackgroundColor(colours.red)
           mon.write(" Off ")
           rs.setBundledOutput(cableSide,colours.subtract(rs.getBundledOutput(cableSide),value.colour))
         end
         
         break
       end end
    end
     
  3. The Snipe

    The Snipe Active Member

    Oh my god thank you! :D I was getting this done very slowly.. and it just wasn't working for me!
     

Share This Page