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

Pneumaticraft Computer contoller

Started by Matachusets2, 25 October 2017 - 12:23 PM
Matachusets2 #1
Posted 25 October 2017 - 02:23 PM
Hello every one, very long time i dont sing in, first its first, thanks for the answers in my R.I.P "Launchpad Controller", when i post that, afther 2 weeks whit no response i didont get in more, but today , i was having problems and when i sing in, i saw my forgoten post, and the answers, maybe later I correct that code for a new launchpad when i go again to the moon or mars ect…

I "recycle" that code to make a brand new Pneumaticraft Air Compressor controller, and i finish it and works, but i like to ask how i can make the program's menu to refres pressure, here is the code:

Spoiler
Aire = peripheral.wrap("back")
presion = Aire.getPressure()
RUN = true
opcion = ""
determinada = ""

function close()
sleep(3)
RUN = false
end

function MENU ()

  term.clear()
  term.setCursorPos(1,1)
  print("	   ----- Air Compressor Controler -----")
  print("WARNING por precaucion este compresor no llegara a 5 bares de presion nunca")
  term.setCursorPos(1,4)
  print("presion maxima : " ..Aire.getDangerPressure())
  term.setCursorPos(1,5)
  print("Presion actual : " ..presion)  --<This one i want to refres to show in the menu the current pressiure at all times
  term.setCursorPos(1,7)
  print("Encender compresor 01")
  print("Apagar compresor 02")
  print("Compresor Automatico 03")
  print("Encender hasta presion determinada 04")
  print("Salir del programa 05")
  term.setCursorPos(1,13)
  print("Seleccion? : ") --posicion 14,13
  term.setCursorPos(14,13)
  opcion = read()

  if opcion == "01" then
  ON()
  elseif opcion == "02" then
  OFF()
  elseif opcion == "03" then
  AUTO()
  elseif opcion == "04" then
  HASTA()
  elseif opcion == "05" then
  Exit()
  end    

end

function ON()
  rs.setOutput("back",true)
  term.setCursorPos(1,16)
  print("Compresor encendido")
  sleep(0.5)
  MENU()
end

function OFF()
  rs.setOutput("back",false)
  term.setCursorPos(1,16)
  print("Compresor apagado")  
  sleep(0.5)
  MENU()
end

function AUTO()
  if presion < 4.5 then
  rs.setOutput("back", true)
  sleep(0.1)
  else
  rs.setOutput("back", false)
  sleep(0.1)
  MENU()
end

end

function HASTA()
  term.setCursorPos(1,15)
  print("hasta que presion? (si el compresor es de 5 bares y la tuberias de 5 bares no se recomienda)")
  term.setCursorPos(1,16)
  determinada = read()

  if presion < determinada then
    rs.setOutput("back",true)
    presion = Aire.getPressure()
    term.setCursorPos(1,17)
    print("comprimiendo.. : " .. presion)
    sleep(0.1)
    elseif presion >=  determinada then
    rs.setOutput("back",false)
    sleep(0.1)
 MENU()
    end
end

function Exit ()
term.clear()
print("hasta la proxima!!!")
close()
end

while RUN do
  MENU()
  term.setCursorPos(1,5) ---fail to do refres
  print("Presion actual : " ..presion)  --same here this one and the other i going to delete, works on menu but no working for refresing.
end


As you all can see, my code is very complex, i could make it more easy and simply, but this way i think is better for learning.
these last 2 lines dont work for refresing, i thing i need a "if bucle" or a "while bucle" for the refresing but didont know where i have to put then and how. Thanks a lot.
Edited on 26 October 2017 - 08:37 AM
Luca_S #2
Posted 26 October 2017 - 08:39 AM
A few things:
1. If you post code in the CC Forums please put it in a code tag, it will be much easier to read:

print("Hello World")
2. If you have code that is really long, like yours I would suggest putting it on pastebin instead of putting all of it in your post
3. Indent your code, it will make it way easier to read. (This is much easier to read, right?)
4. Be more consistent in how you name your variables/functions(e.g. you have Exit() with a uppercase first letter and then lowercase, close() with only lowercase and MENU(), HASTA(), etc. with all uppercase)
5. Try to name your variables in english it will make it much easier for someone else to understand what's going on.

Ok with these out of the way the problem in your code is probably that you only set the variable presion once and do not update it before drawing it to the screen, try adding

presion = Aire.getPressure()
everytime before you print out presion to the screen, this should make it update.
Matachusets2 #3
Posted 04 December 2017 - 01:15 AM
Ok, thanks, and sorry about posting all the code whiout the spoiler buton, i dont post much on forums, i ususally read 99.99% of the time, next time i try to dont forget at least the spoiler buton. As for the program i modified it, a few bugs and some mistakes i notice afther running some time it, for example the auto function, it shut off the compresor, BUT… shut off all, never go on again if presion or "pressure" in english, go down. i post the program agaain once i have it bug free and on a decent working state, then i try to add more complex things. Thanks again.