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

HELP WITH PRESSURE CONTROLLER

Started by RedstonMaster, 06 October 2016 - 05:39 PM
RedstonMaster #1
Posted 06 October 2016 - 07:39 PM
I have a program in computercraft to control the pressure from pneumatic craft pressure chamber . someone can tell me what's wrong?

there is pastebin link: http://pastebin.com/HYzrTpRs
Lupus590 #2
Posted 06 October 2016 - 08:06 PM
What is it doing that you think is wrong and what do you want it to do instead?
RedstonMaster #3
Posted 07 October 2016 - 02:11 PM
When I put on the program the monitor doesn't write nothing on the screen , It writes only when preassure is higher
Sillyjake #4
Posted 07 October 2016 - 06:51 PM
Try making a loop where it displays it, run it in a co-routine.
Dog #5
Posted 07 October 2016 - 07:02 PM
Try making a loop where it displays it, run it in a co-routine.
A co-routine is overkill for this.

RedstonMaster - the biggest problem I'm seeing in your script is that you set presionActual only once before you start waiting for redstone events and then never check it again. I would recommend adding another check just after the redstone event check - then presionActual will be updated each loop and the program will be able to act accordingly.

...
os.pullEvent("redstone")
presionActual = p.getPressure()
...

Also, you can eliminate the peripheral wrap for the monitor within your loop - that only needs to be done once and you've already done it before the loop.
RedstonMaster #6
Posted 08 October 2016 - 01:25 PM
Try making a loop where it displays it, run it in a co-routine.
A co-routine is overkill for this.

RedstonMaster - the biggest problem I'm seeing in your script is that you set presionActual only once before you start waiting for redstone events and then never check it again. I would recommend adding another check just after the redstone event check - then presionActual will be updated each loop and the program will be able to act accordingly.

...
os.pullEvent("redstone")
presionActual = p.getPressure()
...

Also, you can eliminate the peripheral wrap for the monitor within your loop - that only needs to be done once and you've already done it before the loop.

Thanks it worked

Edit:

Well it's not working now when I start the program the monitor shows the pression but it don't update the pressure

that's what I did http://pastebin.com/esLsB4W4
Edited on 08 October 2016 - 12:30 PM
Bomb Bloke #7
Posted 08 October 2016 - 02:33 PM
Are you actually toggling the redstone signal to the computer? This line here:

os.pullEvent("redstone")

… will cause it to yield until a redstone signal provided to the system either activates or de-activates.

If you are, then odds are the sleep(1) call is causing the problem - if the state change occurs while the system is sleeping, it won't be able to detect it when you later specifically stop to wait for a redstone event! You'll certainly want to remove that line.
RedstonMaster #8
Posted 08 October 2016 - 10:56 PM
Are you actually toggling the redstone signal to the computer? This line here:

os.pullEvent("redstone")

… will cause it to yield until a redstone signal provided to the system either activates or de-activates.

If you are, then odds are the sleep(1) call is causing the problem - if the state change occurs while the system is sleeping, it won't be able to detect it when you later specifically stop to wait for a redstone event! You'll certainly want to remove that line.

????????????????????????????????????????????????????????
hbomb79 #9
Posted 08 October 2016 - 11:07 PM
????????????????????????????????????????????????????????

That doesn't really help BombBloke understand which part of the answer you are having issues with.

In simple terms:
While the computer is sleeping, it 'eats events' due to the way sleep functions (it waits for a timer event using iteration, any events caught before that are ignored)

If your redstone state is being toggled while the computer is still sleeping, the `redstone` event fired as a result of the change will be ignored by the sleep function.

You could check if the redstone is in the desired state using `redstone.getInput` straight after the sleep call. If it is not correct, then - and only then `os.pullEvent "redstone"`. Then, if the `redstone` event was fired during the sleep, it doesn't matter because you won't be waiting for one.

It is probably best to remove the unneeded sleep as BombBloke suggested.
RedstonMaster #10
Posted 09 October 2016 - 08:19 AM
????????????????????????????????????????????????????????

That doesn't really help BombBloke understand which part of the answer you are having issues with.

In simple terms:
While the computer is sleeping, it 'eats events' due to the way sleep functions (it waits for a timer event using iteration, any events caught before that are ignored)

If your redstone state is being toggled while the computer is still sleeping, the `redstone` event fired as a result of the change will be ignored by the sleep function.

You could check if the redstone is in the desired state using `redstone.getInput` straight after the sleep call. If it is not correct, then - and only then `os.pullEvent "redstone"`. Then, if the `redstone` event was fired during the sleep, it doesn't matter because you won't be waiting for one.

It is probably best to remove the unneeded sleep as BombBloke suggested.

thats what I did http://pastebin.com/Bgu2N777
hbomb79 #11
Posted 09 October 2016 - 08:41 AM
Did you? I still see a sleep function call in there…

Is the issue resolved?
Edited on 09 October 2016 - 06:44 AM
RedstonMaster #12
Posted 09 October 2016 - 08:55 AM
Did you? I still see a sleep function call in there…

Is the issue resolved?
I erased the sleep function but now the monitor only shows pressure while is higher than presiónMaxima

Did you? I still see a sleep function call in there…

Is the issue resolved?
I erased the sleep function but now the monitor only shows pressure while is higher than presiónMaxima and I have the issue too long without yielding
hbomb79 #13
Posted 09 October 2016 - 08:57 AM
Too long without yielding is because you have no event yielding. That means os.pullEvent or sleep functions are needed, else your program will loop forever.

What was the problem with the sleep function being used?
RedstonMaster #14
Posted 09 October 2016 - 08:58 AM
TOO LONG WITHOUT YIELDING
hbomb79 #15
Posted 09 October 2016 - 09:02 AM
With the sleep command?
RedstonMaster #16
Posted 09 October 2016 - 09:15 AM
.
Too long without yielding is because you have no event yielding. That means os.pullEvent or sleep functions are needed, else your program will loop forever.

What was the problem with the sleep function being used?
I donn't know :(/>

.
Too long without yielding is because you have no event yielding. That means os.pullEvent or sleep functions are needed, else your program will loop forever.

What was the problem with the sleep function being used?
I donn't know :(/>

.
Too long without yielding is because you have no event yielding. That means os.pullEvent or sleep functions are needed, else your program will loop forever.

What was the problem with the sleep function being used?
I donn't know :(/>

.
Too long without yielding is because you have no event yielding. That means os.pullEvent or sleep functions are needed, else your program will loop forever.

What was the problem with the sleep function being used?
I donn't know :(/>
now the program doesn't work, now the screen is empty

sorry for repeating the post
hbomb79 #17
Posted 09 October 2016 - 09:19 AM
What do you mean, you don't know; What is wrong with the program when the sleep command is used?
Edited on 09 October 2016 - 07:19 AM
RedstonMaster #18
Posted 09 October 2016 - 10:19 AM
What do you mean, you don't know; What is wrong with the program when the sleep command is used?
I don't know that's I did http://pastebin.com/p6yaifwR
RedstonMaster #19
Posted 09 October 2016 - 10:56 AM
What do you mean, you don't know; What is wrong with the program when the sleep command is used?
It doesn't write the pressure in the monitor
Bomb Bloke #20
Posted 09 October 2016 - 11:02 AM
It does, but you nearly immediately clear it away:

  monitor.write(presionActual)
  monitor.setCursorPos(1,1)
  monitor.clear()

Try it like:

  monitor.setCursorPos(1,1)
  monitor.clear()
  monitor.write(presionActual)
RedstonMaster #21
Posted 09 October 2016 - 06:57 PM
It does, but you nearly immediately clear it away:

  monitor.write(presionActual)
  monitor.setCursorPos(1,1)
  monitor.clear()

Try it like:

  monitor.setCursorPos(1,1)
  monitor.clear()
  monitor.write(presionActual)
now the program is stopped at 0.29912 presure

It does, but you nearly immediately clear it away:

  monitor.write(presionActual)
  monitor.setCursorPos(1,1)
  monitor.clear()

Try it like:

  monitor.setCursorPos(1,1)
  monitor.clear()
  monitor.write(presionActual)
now the program is stopped at 0.29912 presure

IT'S WORKING OHHHH YEAH IT'S WORKING :DDDDDDDDDDDD :rolleyes:/> :rolleyes:/> :rolleyes:/> :rolleyes:/> :rolleyes:THAAAAAAAAAAAAAAAAAAAAAAANKS