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

Working with monitors

Started by Simmons928, 21 June 2014 - 02:40 AM
Simmons928 #1
Posted 21 June 2014 - 04:40 AM
I am having a problem with information being output on mon1. There are 2 functions that write to the monitor. This is being used to manager a big reactor reactor. Please let me know if you need more information.

Function that I am having trouble with:

function mainScrOut()
powerStore = reactor.getEnergyStored()
energyProd = reactor.getEnergyProducedLastTick()
fuelReact = reactor.getFuelReactivity()
fuelUsed = reactor.getFuelConsumedLastTick()
mon1.setCursorPos(10,1)
mon1.write("The reactor is now managing itself")
mon1.setCursorPos(10,2)
mon1.write("---------------------------------------------------")
mon1.setCursorPos(10,3)
mon1.write("Number of Control rods in reactor? "..numOfContRod)
mon1.setCursorPos(10,4)
mon1.write("Fuel use per Tick: "..fuelUsed)
mon1.setCursorPos(10,5)
mon1.write("Power Stored: "..powerStore)
mon1.setCursorPos(10,6)
mon1.write("Energy p/tic: "..energyProd)
mon1.setCursorPos(10,7)
mon1.write("Fuel reactivity: "..fuelReact)
end

This is the other function that uses that monitor and everything writes from here just fine:

function rodLevels()
mon1.clear()
rod1Level = reactor.getControlRodLevel(0)
rod2Level = reactor.getControlRodLevel(1)
rod3Level = reactor.getControlRodLevel(2)
rod4Level = reactor.getControlRodLevel(3)
rod5Level = reactor.getControlRodLevel(4)
rod6Level = reactor.getControlRodLevel(5)
rod7Level = reactor.getControlRodLevel(6)
rod8Level = reactor.getControlRodLevel(7)
rod9Level = reactor.getControlRodLevel(8)
rod10Level = reactor.getControlRodLevel(9)
rod11Level = reactor.getControlRodLevel(10)
rod12Level = reactor.getControlRodLevel(11)
mon1.setCursorPos(1,1)
mon1.write("R 1: "..rod1Level)
mon1.setCursorPos(1,2)
mon1.write("R 2: "..rod2Level)
mon1.setCursorPos(1,3)
mon1.write("R 3: "..rod3Level)
mon1.setCursorPos(1,4)
mon1.write("R 4: "..rod4Level)
mon1.setCursorPos(1,5)
mon1.write("R 5: "..rod5Level)
mon1.setCursorPos(1,6)
mon1.write("R 6: "..rod6Level)
mon1.setCursorPos(1,7)
mon1.write("R 7: "..rod7Level)
mon1.setCursorPos(1,8)
mon1.write("R 8: "..rod8Level)
mon1.setCursorPos(1,9)
mon1.write("R 9: "..rod9Level)
mon1.setCursorPos(1,10)
mon1.write("R10: "..rod10Level)
mon1.setCursorPos(1,11)
mon1.write("R11: "..rod11Level)
mon1.setCursorPos(1,12)
mon1.write("R12: "..rod12Level)
end









reactor = peripheral.wrap("right")
modem = peripheral.wrap("back")
mon1 = peripheral.wrap("monitor_8")
mon2 = peripheral.wrap("monitor_7")
mon3 = peripheral.wrap("monitor_9")
mon4 = peripheral.wrap("monitor_10")
mon5 = peripheral.wrap("monitor_11")
mon6 = peripheral.wrap("monitor_6")
connected = reactor.getConnected()
numOfContRod = reactor.getNumberOfControlRods()
active = reactor.getActive()
runtime = 0
errors = 0
lastPowerStore = 0
--Monitor 1 formatting
mon1.setBackgroundColor(colors.white)
mon1.setTextColor(colors.black)
mon1.setTextScale(1)
mon1.clear()
--Monitor 2 formatting
mon2.setBackgroundColor(colors.white)
mon2.setTextColor(colors.black)
mon2.setTextScale(1)
mon2.clear()
--Monitor 3 formatting
mon3.setBackgroundColor(colors.white)
mon3.setTextColor(colors.black)
mon3.setTextScale(1)
mon3.clear()
--Monitor 4 formatting
mon4.setBackgroundColor(colors.white)
mon4.setTextColor(colors.black)
mon4.setTextScale(1)
mon4.clear()
--Monitor 5 formatting
mon5.setBackgroundColor(colors.white)
mon5.setTextColor(colors.black)
mon5.setTextScale(1)
mon5.clear()
--Monitor 6 formatting
mon1.setBackgroundColor(colors.white)
mon1.setTextColor(colors.black)
mon1.setTextScale(2)
mon1.clear()

conRodLvl = 100
maxPower = 7500000
minPower = 5000000
maxCaseTemp = 700
maxFuelTemp = 2500
function rodLevels()
mon1.clear()
rod1Level = reactor.getControlRodLevel(0)
rod2Level = reactor.getControlRodLevel(1)
rod3Level = reactor.getControlRodLevel(2)
rod4Level = reactor.getControlRodLevel(3)
rod5Level = reactor.getControlRodLevel(4)
rod6Level = reactor.getControlRodLevel(5)
rod7Level = reactor.getControlRodLevel(6)
rod8Level = reactor.getControlRodLevel(7)
rod9Level = reactor.getControlRodLevel(8)
rod10Level = reactor.getControlRodLevel(9)
rod11Level = reactor.getControlRodLevel(10)
rod12Level = reactor.getControlRodLevel(11)
mon1.setCursorPos(1,1)
mon1.write("R 1: "..rod1Level)
mon1.setCursorPos(1,2)
mon1.write("R 2: "..rod2Level)
mon1.setCursorPos(1,3)
mon1.write("R 3: "..rod3Level)
mon1.setCursorPos(1,4)
mon1.write("R 4: "..rod4Level)
mon1.setCursorPos(1,5)
mon1.write("R 5: "..rod5Level)
mon1.setCursorPos(1,6)
mon1.write("R 6: "..rod6Level)
mon1.setCursorPos(1,7)
mon1.write("R 7: "..rod7Level)
mon1.setCursorPos(1,8)
mon1.write("R 8: "..rod8Level)
mon1.setCursorPos(1,9)
mon1.write("R 9: "..rod9Level)
mon1.setCursorPos(1,10)
mon1.write("R10: "..rod10Level)
mon1.setCursorPos(1,11)
mon1.write("R11: "..rod11Level)
mon1.setCursorPos(1,12)
mon1.write("R12: "..rod12Level)
end
function tempCheck()
mon4.clear()
mon5.clear()
caseTemp = reactor.getCasingTemperature()
mon4.setCursorPos(1,1)
mon4.write("Case Temp")
mon4.setCursorPos(1,2)
mon4.write(caseTemp)
fuelTemp = reactor.getFuelTemperature()
mon5.setCursorPos(1,1)
mon5.write("Fuel Temp")
mon5.setCursorPos(1,2)
mon5.write(fuelTemp)
if caseTemp>maxCaseTemp then
reactor.setAllControlRodLevels(100)
while caseTemp>maxCaseTemp do
  sleep(1)
  mon4.setBackgroundColor(colors.red)
  mon4.setBackgroundColor(colors.white)
  caseTemp = reactor.getCasingTemperature()
  errors = errors+1
end
elseif fuelTemp>maxFuelTemp then
reactor.setAllControlRodLevels(100)
while fuelTemp>maxFuelTemp do
  sleep(1)
  mon5.setBackgroundColor(colors.yellow)
  mon5.setBackgroundColor(colors.white)
  fuelTemp = reactor.getFuelTemperature()
  errors = errors+1
end
end
end
function fuelCheck()
mon2.clear()
mon3.clear()
currentFuel = reactor.getFuelAmount()
amountWaste = reactor.getWasteAmount()
maxFuel = reactor.getFuelAmountMax()
waste = (amountWaste/currentFuel)*100
fuel = (currentFuel/maxFuel)*100
mon2.setCursorPos(1,1)
mon2.write("Fuel")
mon2.setCursorPos(1,2)
mon2.write(fuel)
mon2.setCursorPos(1,3)
mon2.write(currentFuel)
if fuel<50 then
mon2.setBackgroundColor(colors.yellow)
else
mon2.setBackgroundColor(colors.white)
end
mon3.setCursorPos(1,1)
mon3.write("Waste")
mon3.setCursorPos(1,2)
mon3.write(waste)
mon3.setCursorPos(1,3)
mon3.write(amountWaste)
if amountWaste>2000 then
mon3.setBackgroundColor(colors.blue)
else
mon3.setBackgroundColor(colors.blue)
end
end
function logic()
maxPower = 7500000
minPower = 5000000
maxCaseTemp = 700
maxFuelTemp = 2500
powerStore = reactor.getEnergyStored()
energyProd = reactor.getEnergyProducedLastTick()
fuelReact = reactor.getFuelReactivity()
fuelUsed = reactor.getFuelConsumedLastTick()
averageRodLevel = (rod1Level+rod2Level+rod3Level+rod4Level+rod5Level+rod6Level+rod7Level+rod8Level+rod9Level+rod10Level+rod11Level+rod12Level)/12
if powerStore<minPower then
if rod1Level>=averageRodLevel then
  rod1Level = rod1Level-1
  if rod1Level<0 then
   rod1Level = 0
  end
  reactor.setControlRodLevel(0,rod1Level)
  sleep(1)
elseif rod2Level>=averageRodLevel then
  rod2Level = rod2Level-1
  if rod2Level<0 then
   rod2Level = 0
  end
  reactor.setControlRodLevel(1,rod2Level)
  sleep(1)
elseif rod3Level>=averageRodLevel then
  rod3Level = rod3Level-1
  if rod3Level<0 then
   rod3Level = 0
  end
  reactor.setControlRodLevel(2,rod3Level)
  sleep(1)
elseif rod4Level>=averageRodLevel then
  rod4Level = rod4Level-1
  if rod4Level<0 then
   rod4Level = 0
  end
  reactor.setControlRodLevel(3,rod4Level)
  sleep(1)
elseif rod5Level>=averageRodLevel then
  rod5Level = rod5Level-1
  if rod5Level<0 then
   rod5Level = 0
  end
  reactor.setControlRodLevel(4,rod5Level)
  sleep(1)
elseif rod6Level>=averageRodLevel then
  rod6Level = rod6Level-1
  if rod6Level<0 then
   rod6Level = 0
  end
  reactor.setControlRodLevel(5,rod6Level)
  sleep(1)
elseif rod7Level>=averageRodLevel then
  rod7Level = rod7Level-1
  if rod7Level<0 then
   rod7Level = 0
  end
  reactor.setControlRodLevel(6,rod7Level)
  sleep(1)
elseif rod8Level>=averageRodLevel then
  rod8Level = rod8Level-1
  if rod8Level<0 then
   rod8Level = 0
  end
  reactor.setControlRodLevel(7,rod8Level)
  sleep(1)
elseif rod9Level>=averageRodLevel then
  rod9Level = rod9Level-1
  if rod9Level<0 then
   rod9Level = 0
  end
  reactor.setControlRodLevel(8,rod9Level)
  sleep(1)
elseif rod10Level>=averageRodLevel then
  rod10Level = rod10Level-1
  if rod10Level<0 then
   rod10Level = 0
  end
  reactor.setControlRodLevel(9,rod10Level)
  sleep(1)
elseif rod11Level>=averageRodLevel then
  rod11Level = rod11Level-1
  if rod11Level<0 then
   rod11Level = 0
  end
  reactor.setControlRodLevel(10,rod11Level)
  sleep(1)
elseif rod12Level>=averageRodLevel then
  rod12Level = rod12Level-1
  if rod12Level<0 then
   rod12Level = 0
  end
  reactor.setControlRodLevel(11,rod12Level)
  sleep(1)
end
elseif powerStore>maxPower then
if rod1Level<=averageRodLevel then
  rod1Level = rod1Level+1
  if rod1Level>100 then
   rod1Level = 100
  end
  reactor.setControlRodLevel(0,rod1Level)
  sleep(1)
elseif rod2Level<=averageRodLevel then
  rod2Level = rod2Level+1
  if rod2Level>100 then
   rod2Level = 100
  end
  reactor.setControlRodLevel(1,rod2Level)
  sleep(1)
elseif rod3Level<=averageRodLevel then
  rod3Level = rod3Level+1
  if rod3Level>100 then
   rod3Level = 100
  end
  reactor.setControlRodLevel(2,rod3Level)
  sleep(1)
elseif rod4Level<=averageRodLevel then
  rod4Level = rod4Level+1
  if rod4Level>100 then
   rod4Level = 100
  end
  reactor.setControlRodLevel(3,rod4Level)
  sleep(1)
elseif rod5Level<=averageRodLevel then
  rod5Level = rod5Level+1
  if rod5Level>100 then
   rod5Level = 100
  end
  reactor.setControlRodLevel(4,rod5Level)
  sleep(1)
elseif rod6Level<=averageRodLevel then
  rod6Level = rod6Level+1
  if rod6Level>100 then
   rod6Level = 100
  end
  reactor.setControlRodLevel(5,rod6Level)
  sleep(1)
elseif rod7Level<=averageRodLevel then
  rod7Level = rod7Level+1
  if rod7Level>100 then
   rod7Level = 100
  end
  reactor.setControlRodLevel(6,rod7Level)
  sleep(1)
elseif rod8Level<=averageRodLevel then
  rod8Level = rod8Level+1
  if rod8Level>100 then
   rod8Level = 100
  end
  reactor.setControlRodLevel(7,rod8Level)
  sleep(1)
elseif rod9Level<=averageRodLevel then
  rod9Level = rod9Level+1
  if rod9Level>100 then
   rod9Level = 100
  end
  reactor.setControlRodLevel(8,rod9Level)
  sleep(1)
elseif rod10Level<=averageRodLevel then
  rod10level = rod10Level+1
  if rod10Level>100 then
   rod10Level = 100
  end
  reactor.setControlRodLevel(9,rod10Level)
  sleep(1)
elseif rod11Level<=averageRodLevel then
  rod11Level = rod11Level+1
  if rod11Level>100 then
   rod11Level = 100
  end
  reactor.setControlRodLevel(10,rod11Level)
  sleep(1)
elseif rod12Level<=averageRodLevel then
  rod12Level = rod12Level+1
  if rod12Level>100 then
   rod121Level = 100
  end
  reactor.setControlRodLevel(11,rod12Level)
  sleep(1)
end
else
sleep(1)
end
end

function mainScrOut()
powerStore = reactor.getEnergyStored()
energyProd = reactor.getEnergyProducedLastTick()
fuelReact = reactor.getFuelReactivity()
fuelUsed = reactor.getFuelConsumedLastTick()
mon1.setCursorPos(10,1)
mon1.write("The reactor is now managing itself")
mon1.setCursorPos(10,2)
mon1.write("---------------------------------------------------")
mon1.setCursorPos(10,3)
mon1.write("Number of Control rods in reactor? "..numOfContRod)
mon1.setCursorPos(10,4)
mon1.write("Fuel use per Tick: "..fuelUsed)
mon1.setCursorPos(10,5)
mon1.write("Power Stored: "..powerStore)
mon1.setCursorPos(10,6)
mon1.write("Energy p/tic: "..energyProd)
mon1.setCursorPos(10,7)
mon1.write("Fuel reactivity: "..fuelReact)
end

function automation()
reactor.setAllControlRodLevels(conRodLvl)
while true do
rodLevels()
tempCheck()
fuelCheck()
logic()
mainScrOut()
runtime = runtime+1
term.clear()
print("current uptime of automation program: "..runtime)
print("number of error seconds: "..errors)
end
end
automation()
Bomb Bloke #2
Posted 21 June 2014 - 04:47 AM
I am having a problem with information being output on mon1. There are 2 functions that write to the monitor. This is being used to manager a big reactor reactor. Please let me know if you need more information.

Question 1: What is the problem?

Are you getting errors?

A malformed display?

Nothing?

What?
Simmons928 #3
Posted 21 June 2014 - 04:53 AM
Oops, that might help. mainScrOut() is not posting to the monitor at all.
No errors pop
I only get the rodLevels() to show up on there
Bomb Bloke #4
Posted 21 June 2014 - 05:31 AM
In that case, I'd say your issue is that you're clearing the screen nearly immediately after calling that function. Try adding in a sleep just before the clear.
Simmons928 #5
Posted 21 June 2014 - 05:48 AM
Let me try that. I am going to move from using the sleeps under logic() to using a single sleep in automation() with another function to clear all the screens after the sleep. I will let you know how it works. :)/>
Simmons928 #6
Posted 21 June 2014 - 06:08 AM
And that did it!! once you explained it, made perfect sense. :D/> Thank you very much for the help!!