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

OpenPeripheral: Very simple battery monitor

Started by Mikeemoo, 04 June 2013 - 02:31 PM
Mikeemoo #1
Posted 04 June 2013 - 04:31 PM
Using ComputerCraft 1.53 and OpenPeripheral 0.1.1

Not the most beautifully written code, but it works.

Stick a computer down, a Glasses Bridge next to it, then lan cables out the back attaching to any IC2 (or IC2 integrated) electricity storage unit.

[media]http://youtu.be/g4xkBGyJqEU[/media]

Configure the storage units below


local bridge = peripheral.wrap("left")
local net = peripheral.wrap("back")

bridge.clear()

local width = 200

local storageUnits = {
   {
	 ["id"] = "batbox_0",
	 ["name"] = "Main Batbox"
   },
   {
	 ["id"] = "batbox_1",
	 ["name"] = "Another Batbox"
   }
}

local offset = 0
for key, storageUnit in pairs(storageUnits) do
  pxOffset = offset * 20
  storageUnit["label"] = bridge.addText(4, 4 + pxOffset, storageUnit["name"], 0x000000)
  storageUnit["bar"] = bridge.addBox(4, 14 + pxOffset, 0, 5, 0xCC0000, 0.9)
  storageUnit["bar"].setZIndex(2)
  storageUnit["bg"] = bridge.addBox(4, 14 + pxOffset, width, 5, 0x000000, 0.5)
  offset = offset + 1
end

while true do
  for i=#storageUnits,1,-1 do
	storageUnit = storageUnits[i]
	if net.isPresentRemote(storageUnit["id"]) then
	  capacity = net.callRemote(storageUnit["id"], "getCapacity")
	  amount = net.callRemote(storageUnit["id"], "getStored")
	  storageUnit["bar"].setWidth(width / capacity * amount)
	else
	  storageUnit["bar"].delete()
	  storageUnit["bg"].delete()
	  storageUnit["label"].delete()
	  table.remove(storageUnits, i)
	end
  end
  sleep(0.5)
end
ETHANATOR360 #2
Posted 04 June 2013 - 09:58 PM
how do you use industrial craft with 1.53 the latest industrial craft download i see is for 1.4.5 and lower
on topic: cool program i love seeing computercraft and IC work together
JustPingo #3
Posted 05 June 2013 - 11:00 AM
It's completly amazing !

Very useful, thanks you guy.
RootSlayers #4
Posted 25 July 2013 - 01:22 PM
Hello,
I can't use this code because I've got an error :
startup:33: No such methode getCapacity
Mitchfizz05 #5
Posted 25 July 2013 - 05:29 PM
Hello,
I can't use this code because I've got an error :
startup:33: No such methode getCapacity
I think you need OpenPeripherals. =\
RootSlayers #6
Posted 26 July 2013 - 07:16 AM
Hello,
I can't use this code because I've got an error :
startup:33: No such methode getCapacity
I think you need OpenPeripherals. =\

Yes I have got OpenPeripheral-0.1.9 and OpenCCSensors-1.5.2.0 with ComputerCraft 1.53 :/

Edit: Its normal that the "openperipheral" is Empty ?
diegodan1893 #7
Posted 26 July 2013 - 08:03 AM
how do you use industrial craft with 1.53 the latest industrial craft download i see is for 1.4.5 and lower
on topic: cool program i love seeing computercraft and IC work together
There is a public Beta that works with minecraft 1.52
RootSlayers #8
Posted 26 July 2013 - 08:49 AM
The lasted version of Industrial Craft is 1.118.401-if right ?
If yes I have it installed with Minecraft 1.5.2.
NeptunasLT #9
Posted 27 July 2013 - 03:19 PM
At what Time ComputerCraft getted batteries?
M4sh3dP0t4t03 #10
Posted 29 July 2013 - 04:55 PM
At what Time ComputerCraft getted batteries?
Read the OP and learn english!
SyberSmoke #11
Posted 30 July 2013 - 02:21 AM
At what Time ComputerCraft getted batteries?

Hurm…BatBox (Bat being short for battery), MFE, MFSU…etc. All batteries.
ShadowXYX #12
Posted 04 August 2013 - 01:32 PM
is there anyway to do { without using ALTGR ? im using a QWERTY keyboard ? help please
ErolDude #13
Posted 04 August 2013 - 06:12 PM
is there anyway to do { without using ALTGR ? im using a QWERTY keyboard ? help please
Use the character map lol, no other way that I know of.
DarkEspeon #14
Posted 24 August 2013 - 03:20 PM
is there anyway to do { without using ALTGR ? im using a QWERTY keyboard ? help please

SHIFT + [ == {
Raythornious #15
Posted 14 September 2013 - 07:13 PM
I love this program you can use it to make some pretty cool setups as long as you know how to edit the program. Also now that its Modular Power Suit compatible I don't have to sacrifice armor :D/>
lollord7819 #16
Posted 19 September 2013 - 11:19 PM
got an error and have no clue how to fix it says: bios:339: [string "power"]:21: '=' expected
yes i realize an = is expected but i have no clue where
Alexander0507 #17
Posted 29 October 2013 - 04:55 PM
How did you get it to automatically refresh ?
descention #18
Posted 06 December 2013 - 11:57 AM
I've added support for redstone energy cells: http://pastebin.com/tTd8yHgh
Chloe #19
Posted 31 December 2013 - 06:58 PM
wrong thread
Edited on 31 December 2013 - 06:01 PM
Bardaky #20
Posted 15 January 2014 - 04:45 PM
I am trying to get ur programm working with 10 mfsu's at the same time, but i cant get it working. the computer keeps on telling me, that i need a "}" behind line 11, to close the "{" from line 9.
This part of the Program is
local storageUnits = {
{
["id"] = "mfsu_0",
["name"] = "Unit 0"
}
}

(only one mfsu to test it)

And it told me before i had all the "name" stuff in there and no "label" that he expected table, but got nil in the line of "for key, storageUnit in pairs(storageUnits) do"

Edit: i found the bug with the "{" i just needed a "," between the two declarations
Edited on 15 January 2014 - 05:01 PM
ByteZz #21
Posted 23 March 2014 - 02:41 AM
Program Used:http://www.computerc...attery-monitor/

I copied this program exactly as it was written, and every time I try to use it it says attempt to call nil. Don't know why, all of the replies I read said it work, but unfortunately I can't reply to the post so that why I am posting about it here. Please help.

Can you tell us what line of the code is the attempt to call nil showing up? I have created a program using this code as well as its base so if you would like it let me know. It is highly customizable.
theoriginalbit #22
Posted 23 March 2014 - 02:42 AM
-snip-
you should also mention which version of OpenPeripheral you're using.
Whizzywig #23
Posted 27 April 2014 - 05:47 PM
When i used it i got a null value every time on line 21 .setZIndex(2) is the problem the code i used is here: http://pastebin.com/uLzhgbjw

Program Used: http://pastebin.com/uLzHgbjw

i kept getting a null value at line 21 and it is the .setZIndex(2). I have tried it in different programs and it doesn't work please help.
ByteZz #24
Posted 27 April 2014 - 06:24 PM
When i used it i got a null value every time on line 21 .setZIndex(2) is the problem the code i used is here: http://pastebin.com/uLzhgbjw

Program Used: http://pastebin.com/uLzHgbjw

i kept getting a null value at line 21 and it is the .setZIndex(2). I have tried it in different programs and it doesn't work please help.

Do you wanna use my program? I can give you the pastebin for it.