Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Valve, Monitor & Wireless Modem
- local val = peripheral.wrap("back")
- local mon = peripheral.wrap("top")
- local wmod = peripheral.wrap("bottom")
- local max = 99 -- Warning level in %
- local min = 10 -- Warning level in %
- local cap -- Tank capacity
- local amount -- Amount liquid in tank
- local percentfull -- Percent liquid in tank
- local lastpercent = 1000 -- Percent last loop
- local sendmsg -- Message to send
- local sleeptime -- How long to sleep
- local sendFreq = 3 -- Modem Frequency
- local content = "Water" -- What is in tank?
- -- Make sure frequency match the main computer
- -- Main prog loop, never stop
- while true do
- -- Fill table with data from tank valve
- tanksTable = val.getTankInfo("WhatIsThis")
- maintank = tanksTable[1]
- -- Get values for tank capacity and amount
- cap = maintank.capacity / 1000 -- in buckets
- amount = maintank.amount -- in millibuckets
- -- If tank is empty, to avoid math issues with 0
- if amount == nil then
- amount = 0
- percentfull = 0
- else
- -- Use math.floor to convert to integers
- amount = math.floor(amount / 1000)
- percentfull = math.floor(100 * amount / cap)
- end
- -- Check for change since last loop
- if percentfull == lastpercent then
- sleep(1)
- else
- -- If value changed, send to main!
- sendmsg = content ..": " ..percentfull .." %"
- wmod.transmit(sendFreq,0,sendmsg)
- end
- -- Save for next loop
- lastpercent = percentfull
- if percentfull < min then
- redstone.setOutput("right", true)
- end
- if percentfull > max then
- redstone.setOutput("right", false)
- end
- sleep(10)
- end
Advertisement
Add Comment
Please, Sign In to add comment