Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This program monitors the power level of a Powah power cell
- -- connected via ComputerCraft networking cables and modems.
- -- **Requires CC: Tweaked 1.113.1 and the Powah mod.**
- -- **Assumes a modem is attached to the BACK of the computer and connected to another modem
- -- attached to the Powah power cell named "powah_cell_modem".**
- -- Set the remote modem's peripheral name
- local remotePeripheralName = "powah_cell_modem"
- -- Set the modem channel (change if needed)
- local modemChannel = 100
- -- Function to check and display the power level
- local function checkPower()
- -- Get the current and max energy levels from the remote modem
- local currentEnergy = peripheral.call(remotePeripheralName, "getEnergyStored")
- local maxEnergy = peripheral.call(remotePeripheralName, "getMaxEnergyStored")
- -- Calculate the percentage of energy stored
- local percentage = (currentEnergy / maxEnergy) * 100
- -- Clear the screen and display the information
- term.clear()
- term.setCursorPos(1, 1)
- print("Powah Power Cell Monitor")
- print("-----------------------")
- print("Current Energy:", currentEnergy)
- print("Max Energy:", maxEnergy)
- print("Percentage:", string.format("%.2f%%", percentage))
- end
- -- Function to set up the modem connection
- local function setupModem()
- -- Get the modem peripheral from the BACK side
- local modem = peripheral.wrap("back")
- -- Open the modem on the specified channel
- modem.open(modemChannel)
- -- Wait for a connection to the remote modem (simplified)
- while true do
- if modem.isOpen(modemChannel) then
- print("Modem is open on channel", modemChannel)
- break -- Exit the loop once the modem is open
- else
- print("Modem not open on channel", modemChannel, ". Waiting...")
- end
- sleep(1)
- end
- end
- -- Setup the modem connection
- setupModem()
- -- Main loop to continuously monitor the power level
- while true do
- checkPower()
- sleep(1) -- Check every second
- end
Advertisement
Add Comment
Please, Sign In to add comment