I´m trying to create a tank monitor program using ccSensors, but i have at few questions.
I have these 3 tanks:
[attachment=476:Tanks.png]
And I get this on my monitor:
[attachment=477:Monitor.png]
My code looks like this:
Spoiler
os.unloadAPI("sensors")os.loadAPI("/rom/apis/sensors")
mon = peripheral.wrap("top")
for i=1,1000 do
mon.setCursorPos(1,1)
mon.write("Fuel Level")
os.sleep(5)
mon.clear()
function printDict(data)
for i,v in pairs(data) do
print(tostring(i).." - "..tostring(v))
end
end
ctrl = sensors.getController()
print(ctrl)
data = sensors.getSensors(ctrl)
printDict(data)
Fuel = data[1]
–Oil = data[2]
data = sensors.getSensorInfo(ctrl,Fuel)
–printDict(data)
–data = sensors.getSensorInfo(ctrl,Oil)
–printDict(data)
sensors.setSensorRange(ctrl,Fuel,"3")
–print(sensors.getSensorInfo(ctrl,Fuel).SensorRange)
data = sensors.getProbes(ctrl,Fuel)
–printDict(data)
liquidTank = data[8]
sensors.setTarget(ctrl,Fuel,liquidTank)
data = sensors.getAvailableTargetsforProbe(ctrl,Fuel,liquidTank)
printDict(data)
–[[Tank1]]–
fuelLevel1 = data[9]
fuelLevel2 = data[6]
fuelLevel3 = data[3]
–[[Tank2]]–
fuelLevel4 = data[8]
fuelLevel5 = data[5]
fuelLevel6 = data[2]
–[[Tank3]]–
fuelLevel7 = data[7]
fuelLevel8 = data[4]
fuelLevel9 = data[1]
data = sensors.getSensorReadingAsDict(ctrl,Fuel,fuelLevel1,liquidTank)
–print(data.stored)
mon.setCursorPos(1,4)
mon.write("Tank 1")
mon.setCursorPos(21,3)
mon.write(data.stored)
data = sensors.getSensorReadingAsDict(ctrl,Fuel,fuelLevel2,liquidTank)
–print(data.stored)
mon.setCursorPos(21,4)
mon.write(data.stored)
data = sensors.getSensorReadingAsDict(ctrl,Fuel,fuelLevel3,liquidTank)
–print(data.stored)
mon.setCursorPos(21,5)
mon.write(data.stored)
data = sensors.getSensorReadingAsDict(ctrl,Fuel,fuelLevel4,liquidTank)
–print(data.stored)
mon.setCursorPos(1,8)
mon.write("Tank 2")
mon.setCursorPos(21,7)
mon.write(data.stored)
data = sensors.getSensorReadingAsDict(ctrl,Fuel,fuelLevel5,liquidTank)
–print(data.stored)
mon.setCursorPos(21,8)
mon.write(data.stored)
data = sensors.getSensorReadingAsDict(ctrl,Fuel,fuelLevel6,liquidTank)
–print(data.stored)
mon.setCursorPos(21,9)
mon.write(data.stored)
data = sensors.getSensorReadingAsDict(ctrl,Fuel,fuelLevel7,liquidTank)
–print(data.stored)
mon.setCursorPos(1,12)
mon.write("Tank 3")
mon.setCursorPos(21,11)
mon.write(data.stored)
data = sensors.getSensorReadingAsDict(ctrl,Fuel,fuelLevel8,liquidTank)
–print(data.stored)
mon.setCursorPos(21,12)
mon.write(data.stored)
data = sensors.getSensorReadingAsDict(ctrl,Fuel,fuelLevel9,liquidTank)
–print(data.stored)
–mon.write(data.stored)
mon.setCursorPos(21,13)
mon.write(data.stored)
end
os.reboot()
I know it is pretty messy, and if any of you got at easier solution let me know.
My question is:
How do i combine "fuelLevel1, fuelLevel2 and fuelLevel3" in to one total value?
Thanks. Thomas.