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

triggering a redstone signal

Question

Hi. I am new to OpenComputers and Lua. I have gotten comfortable with building computers and installing OpenComputers onto my hard drive. 
Currently I have:

 tier 3 case with:

tier 3 cpu
tier 3 hard drive
tier 2 hard drive 
tier 3 memory x 2
tier 3 graphics card 
tier 2 redstone card
internet card

I have a line of redstone coming off the right side of the cpu case if you are looking at it from the front, and the redstone goes to a Dispenser with fireworks in it. 

I then have a line of redstone coming off the front side of the cpu case to a block of diamond with a lever on the front. 

If I flip the lever a redstone signal runs to the cpu.

I can use redstone.getInput(front) to find out it is getting a value of 10. 

I want to send a redstone signal out the side to the dispenser, then shut it off, check the front, if signal still at 10 then send another signal out the side. 

so far here is my code:
local component = require("component")
local sides - require("sides")
local colors = require("colors")
local redstone = component.redstone

local function main()
local firecount =- 1
local signal =- redstone.getInput(front)

 redstone.getInput(front)

If signal == 10 then 
   repeat
     print("Redstone Lever ON")
     print("Firing FIrework!" firecount)

     redstone.setOutput(sides.left,15)
     firecount ++

     os.sleep(1)

     redstone.setOutput(sides.left, 0)

     os.sleep(1)

Else

  print("Lever is OFF")

End

while true do
   main()

End



Any help? 
 

Thanks.

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

First, use code blocks. Second, i fixed your errors and made a few improvements. This should do what you wanted, if not reply in this thread.

local component = require("component")
local sides = require("sides")
local colors = require("colors") --Unused
local event = require("event")
local term = require("term")

local redstone = component.redstone

local firecount = 1
local run = true

local function main()
    local input = redstone.getInput(sides.front)

    if (input == 10) then
        print("Redstone Lever ON")

        print("Firing Firework " .. firecount .. "!")
        firecount = firecount + 1

        redstone.setOutput(sides.left, 15)
        os.sleep(1)
        redstone.setOutput(sides.left, 0)

        os.sleep(1)
    else
        print("Lever is OFF")
        os.sleep(1)
    end
end

--Exit the loop with 'q', better than using Ctrl+C
local function stop(_, _, char)
    if (char == 81 or char == 113) then
        event.ignore("key_down", stop)
        run = false
    end
end

--Print the prompt for quit key and start listening for it
print("press 'q' to exit")
event.listen("key_down", stop)

--Main loop, will run until 'run' is set to false
while run do
    main()
end

--Clear the screen after the program ends
term.clear()

 

Share this post


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.