Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --create an OS timer for waiting for key
- local myTimer = os.startTimer(0)
- --thresholds, to be changed as per the requirement
- local threshlow = 5
- local threshhigh = 10
- --hysteresis low means that it keeps on until
- --it hits high threshold
- --hysteresis high means that it keeps on until
- --it hits low threshold
- --starts in a low state
- local hyst = 'low'
- -- wrap the peripherals
- nc = peripheral.wrap('left')
- mon = peripheral.wrap('top')
- --start us in an off state
- redstone.setOutput('left', false)
- while true do
- local event, param1 = os.pullEvent()
- if event == "timer" and param1 == myTimer then
- md = nc.getMetadata()
- energy = md['energy']
- state = md['state']
- stored = energy['stored']
- capacity = energy['capacity']
- state = state['active']
- percent = math.floor((stored/capacity)*100)
- print(stored, capacity, percent)
- print(state)
- if percent < threshlow then
- redstone.setOutput('left', true)
- hyst = 'high'
- elseif percent > threshhigh then
- redstone.setOutput('left', false)
- hyst = 'low'
- elseif hyst == 'low' then
- redstone.setOutput('left', false)
- else
- redstone.setOutput('left', true)
- end
- mon.setCursorPos(1,1)
- mon.write('Thresh Low: ' .. threshlow .. ' ')
- mon.setCursorPos(1,2)
- mon.write('Thresh High: ' .. threshhigh .. ' ')
- mStored = math.floor(stored/100000)/10
- sStored = string.format("%.1f", mStored)
- mon.setCursorPos(1,3)
- mon.write('Stored: ' .. sStored .. ' MRF ')
- mCapacity = math.floor(capacity/100000)/10
- sCapacity = string.format("%.1f", mCapacity)
- mon.setCursorPos(1,4)
- mon.write('Capacity: ' .. sCapacity .. ' MRF ')
- mon.setCursorPos(1,5)
- mon.write('Percent Full: ' .. percent .. '% ')
- mon.setCursorPos(1,6)
- if state == true then
- mon.write('Reactor Active ')
- else
- mon.write('Reactor Inactive ')
- end
- myTimer = os.startTimer(2)
- elseif event == 'char' and param1 == 'q' then
- redstone.setOutput('left', false)
- mon.clear()
- mon.setCursorPos(1,1)
- mon.write('Program Inactive')
- break
- end
- end
Add Comment
Please, Sign In to add comment