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

Help with a basic power monitoring program

Started by SkyDevil_, 29 July 2015 - 12:39 AM
SkyDevil_ #1
Posted 29 July 2015 - 02:39 AM
Current code:
http://pastebin.com/7eNAdg9e

Hi, Im writing a basic code to monitor a powercube. I managed to get most of it working but i cant seem to get the total RF usage to work correctly currently its just adding to it self over and over.


usage = current-test.getEnergyStored()
m.write("Usage: "..usage)

I belive it has something to do with the "current" Value but i can work out how to fix it.

Could anyone offer any addvice?

Thanks Sky
KingofGamesYami #2
Posted 29 July 2015 - 03:43 AM
Please clarify, what exactly do you expect "Usage" to be? To me, it should be the difference between the power in the cube at the start of the program, and the current power level. As you remove energy from the cube, it will go up. As you add energy to the cube, it will go down.
SkyDevil_ #3
Posted 29 July 2015 - 04:05 AM
Hi, Thanks for reply i was expecting "Usage" to be mor of how much RF is being used per a seconed.
KingofGamesYami #4
Posted 29 July 2015 - 06:29 AM
In that case, you should modify your code to update the 'current' variable each time the loop runs, with the 1 second delay between it and the usage. For example:


local current
while true do
  current = test.getEnergyStored()
  sleep( 1 )
  print( "Usage: " .. current - test.getEnergyStored() )
end
SkyDevil_ #5
Posted 30 July 2015 - 02:09 AM
Hi thanks its fixed my issue but the rf usage a seconded seems to not match up with whats actually being used.
like its say its 15,000rf but ita actually using 20,000 rf
Edited on 30 July 2015 - 12:11 AM
KingofGamesYami #6
Posted 30 July 2015 - 04:29 AM
If you are adding RF to the cube, say 5k RP / second, the program will indeed be off. Also, it simply calculates how much has been used in the last second, not an average.