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

Need help for a simple alarm system

Started by PixelMiner, 01 May 2013 - 08:55 AM
PixelMiner #1
Posted 01 May 2013 - 10:55 AM
Title: Need help for a simple alarm system

Hello guys :)/>

First I need to say that I literaly started using ComputerCraft 2 days ago, so I'm a complete noob (applies to LUA as well) :)/>

On the subject.

I have multiple combustion engines constantly running, but for some reason (don't know if it's a bug or not) after a while the water stops flowing and eventually they just blow up, destroying all my work. After a while I figured that the only way to restore the water flow is by restarting the server. So to prevent my engines from from blowing my place, I started using redstone waterproof pipes. When there's a water in the pipe, it emits redstone signal that powers the engine. As soon as it empites, the engine stops. So far, so good. The thing is that I can't watch them all the time, so I need some sort of an alarm, that will "tell" me when an engine has stopped, so I can restart the server.

I did some googling, watched a crapload of tutorials and found a few codes, that if combined they'd do the job. But due to my "knowledge" in ComputerCraft, I couldn't make it work :/

Here's what I need:

Basically, It's a lamp, that starts flashing as soon as the computer stops recieving redstone signal from the pipe. Additionally, if for some reson the water flow starts again w/out restarting the server, the program goes back to "monitoring" state.




The code



And the error message I get



Thanks in advance and please excuse my crappy English
BigSHinyToys #2
Posted 01 May 2013 - 12:03 PM
Your pictures haven't worked correctly but this code should do it.

Spoiler

local lightSide = "right"
local InputSide = "left"
local toggleLight = true
local myTimer = os.startTimer(0.5)
while true do
    local event,event2 = os.pullEvent()
    if event == "timer" and event2 == myTimer then
	    toggleLight = not toggleLight
	    rs.setOutput(lightSide,toggleLight)
    elseif event == "redstone" then
	    if rs.getInput(InputSide) then
		    myTimer = nil
	    else
		    myTimer = os.startTimer(0.5)
	    end
    end
end
remiX #3
Posted 01 May 2013 - 12:06 PM
Code picture is broken.
PixelMiner #4
Posted 01 May 2013 - 12:17 PM
Don't know why the pics fail for you guys. They work just fine for me..

Anyways, here's the direct links:

http://s13.postimg.org/e247dg2ol/2013_05_01_17_10_55.png
http://s13.postimg.org/43j8qyt91/2013_05_01_17_12_34.png
http://s13.postimg.org/x4nl0ddp1/2013_05_01_17_12_58.png

Thanks for the code, Lua God (mine is not even close to this [lol?]). Gonna try it right away :)/>
remiX #5
Posted 01 May 2013 - 12:48 PM
The first and last pictures are fine, the middle one (Code one) is broken)

PS: His name isn't Lua God, that's his title. His name is BigSHinyToys

Your code:
while rs.getInput("back") == true do
    rs.setOutput("right", false)
else
    print("some warning message")
    rs.setOutput("right", true)
    sleep(2)
    rs.setOutput("right", false)
    sleep(2)
end -- while
end

Few problems:
- a while loop has no else block for it
- 1 too many end

What you wanted was this?
Infinite loop that checks the redstone state of the back input. If it is on, it turns it off. If it is off, it prints "some warning message", puts right signal on and puts it off after 2 seconds?


while true do                                            -- infinite loop
    if rs.getInput("back") then                    -- if statement: if <condition> then do this else do that. Same thing as doing if rs.getInput("back") == true
        rs.setOutput("back", false)              -- turn back redstone signal off
    else
        print("Some warning message")      -- print
        rs.setOutput("right", true)                -- set right redstone true
        sleep(2)                                           -- sleep
        rs.setOutput("right", false)               -- set right redstone false
        sleep(2)
    end                                                      -- end if
end                                                          -- end while
PixelMiner #6
Posted 01 May 2013 - 01:00 PM
The first and last pictures are fine, the middle one (Code one) is broken)

Here's the code (don't laugh :D/>/>)

while rs.getInput ("back") == true do
rs.setOutput ("right", false)
else
rs.setOutput ("right", true)
sleep(2)
rs.setOutput ("right", false)
sleep(2)
end--while
end



PS: His name isn't Lua God, that's his title. His name is BigSHinyToys
Sorry about that :D/>

@BigSHinyToys, the code worked partially (I guess). The lamp starts flashing when there's no rs signal, but it won't stop flashing when the rs signal is restored
PixelMiner #7
Posted 01 May 2013 - 01:21 PM

What you wanted was this?
Infinite loop that checks the redstone state of the back input….

Yes
If the back input is ON, then the right output is OFF.
If the back input is OFF, then the right output starts flashing (ON/OFF loop) along with a printed message (optional)
If the back input comes ON again, then the right output goes OFF and the back input starts checking the rs state again
remiX #8
Posted 01 May 2013 - 01:24 PM

What you wanted was this?
Infinite loop that checks the redstone state of the back input….

Yes
If the back input is ON, then the right output is OFF.
If the back input is OFF, then the right output starts flashing (ON/OFF loop) along with a printed message (optional)
If the back input comes ON again, then the right output goes OFF and the back input starts checking the rs state again

What you wanted was this?
Infinite loop that checks the redstone state of the back input….

Yes
If the back input is ON, then the right output is OFF.
If the back input is OFF, then the right output starts flashing (ON/OFF loop) along with a printed message (optional)
If the back input comes ON again, then the right output goes OFF and the back input starts checking the rs state again

You can edit your posts by the way :P/>

Check my code below that?
PixelMiner #9
Posted 01 May 2013 - 01:40 PM
Yeah, sorry about the doule post :/

Tried your code and it acts the same way as BigSHinyToys' one. It makes the lamp flashing when there's no rs signal on the back input. But when the rs signal is restored, the lamp wont stop flashing
BigSHinyToys #10
Posted 01 May 2013 - 02:01 PM
try this
Spoiler

local lightSide = "back"
local InputSide = "left"
local toggleLight = true
local myTimer = os.startTimer(0.5)
while true do
    local event,event2 = os.pullEvent()
    if event == "timer" and event2 == myTimer then
	    toggleLight = not toggleLight
	    rs.setOutput(lightSide,toggleLight)
    elseif event == "redstone" then
	    if rs.getInput(InputSide) then
		    myTimer = nil
		    rs.setOutput(lightSide,false)
	    else
		    myTimer = os.startTimer(0.5)
	    end
    end
end
also are you using RP or real readstone might make a difference not shore
PixelMiner #11
Posted 01 May 2013 - 02:19 PM
try this
Spoiler

local lightSide = "back"
local InputSide = "left"
local toggleLight = true
local myTimer = os.startTimer(0.5)
while true do
	local event,event2 = os.pullEvent()
	if event == "timer" and event2 == myTimer then
		toggleLight = not toggleLight
		rs.setOutput(lightSide,toggleLight)
	elseif event == "redstone" then
		if rs.getInput(InputSide) then
			myTimer = nil
			rs.setOutput(lightSide,false)
		else
			myTimer = os.startTimer(0.5)
		end
	end
end
also are you using RP or real readstone might make a difference not shore

Nope, doesn't work. Now the back input is always ON even if the pipe is OFF (no water in it). The lamp doesn't work either.

P.S. ummm…. I'm using red alloy wiring, if that's what you mean by RP
BigSHinyToys #12
Posted 01 May 2013 - 02:37 PM
what side is what device on ??
BigSHinyToys #13
Posted 01 May 2013 - 02:43 PM
ok i worked out the probblem
Spoiler

local lightSide = "right" -- edit this
local InputSide = "back" -- edit this
local toggleLight = false
local myTimer = os.startTimer(0.5)
for key,value in pairs(rs.getSides()) do
rs.setOutput(value,false)
end
while true do
local event,event2 = os.pullEvent()
if event == "timer" and event2 == myTimer then
  toggleLight = not toggleLight
  rs.setOutput(lightSide,toggleLight)
  myTimer = os.startTimer(0.5)
elseif event == "redstone" then
  if rs.getInput(InputSide) then
   myTimer = nil
   rs.setOutput(lightSide,false)
  else
   myTimer = os.startTimer(0.5)
  end
end
end
PixelMiner #14
Posted 01 May 2013 - 02:52 PM
Back side is connected to a redstone waterproof pipe. The right side is connected to a red lamp.

While the pipe is full of water, it emits a redstone signal and it powers a combustion engine. If there's a water flow failure, the pipe gets empty and it stops emiting redstone signal, and so the engine stops. Now all I need is the back side to do a constant monitoring to that pipe, so when it stop emmiting rs signal, the red lamp on the right side should start flashing. When the pipe gets full again, the lamp should stop flashing.

In a few words - back side is used ONLY to check for rs signal. And when it detects that there's no signal, it should trigger the flashing red lamp, which is connected to the right side. When the rs signal is restored to the back side, the lamp should go off.

Sorry, can't explain it better :/

EDIT:

ok i worked out the probblem
Spoiler

local lightSide = "right" -- edit this
local InputSide = "back" -- edit this
local toggleLight = false
local myTimer = os.startTimer(0.5)
for key,value in pairs(rs.getSides()) do
rs.setOutput(value,false)
end
while true do
local event,event2 = os.pullEvent()
if event == "timer" and event2 == myTimer then
  toggleLight = not toggleLight
  rs.setOutput(lightSide,toggleLight)
  myTimer = os.startTimer(0.5)
elseif event == "redstone" then
  if rs.getInput(InputSide) then
   myTimer = nil
   rs.setOutput(lightSide,false)
  else
   myTimer = os.startTimer(0.5)
  end
end
end

I love you! Exactly what I need! :)/>
Thankies!