Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dofile("graph")
- local colorToggler = {}
- colorToggler.toggled = false
- colorToggler.color1 = colors.red
- colorToggler.color2 = colors.pink
- function colorToggler:getColor()
- self.toggled = not self.toggled
- return (self.toggled and self.color1 or self.color2)
- end
- local myGraph = graph.new()
- myGraph:setHighValue(70)
- myGraph:addData(10)
- myGraph:addData(20)
- myGraph:addData(30)
- myGraph:addData(5)
- myGraph:setBarWidth(3)
- myGraph:setBarColor(colorToggler)
- local data = {}
- local min = 0
- local max = 0
- local avg = 0
- local cur = 0
- m=peripheral.wrap("bottom")
- m2 = peripheral.wrap("right")
- local w,h = m2.getSize()
- myGraph:setPos(4,1)
- myGraph:setSize(w-3,h)
- myGraph:setMonitor(m2)
- m2.clear()
- m2.setTextColor(colors.white)
- m2.setBackgroundColor(colors.black)
- for i=h,1,-1 do
- m2.setCursorPos(1,i)
- local p = h-i+1
- local perc = 80/h
- local pp = math.floor(perc*p)
- m2.write(string.format("%d",pp))
- end
- function updateScreen()
- m.clear()
- m.setCursorPos(1,1)
- m.write("Falls: "..cur.." (Min: "..min.."/Max: "..max..")")
- m.setCursorPos(1,2)
- m.write("Status: not broken")
- m.setCursorPos(1,3)
- m.write("Tests: " ..#data.." Avg: " ..avg)
- end
- updateScreen()
- function test()
- rs.setOutput("back",true)
- sleep(0.2)
- rs.setOutput("back",false)
- end
- function calcAvg()
- avg = 0
- for k,v in pairs(data) do
- avg = avg + v
- end
- avg = avg / #data
- end
- myGraph:draw()
- test()
- while true do
- os.pullEvent("redstone")
- if rs.getBundledInput("front") == 1 then
- cur=cur+1
- updateScreen()
- test()
- elseif rs.getBundledInput("front") == 2 then
- m.setCursorPos(1,2)
- m.write("Status: broken")
- table.insert(data,cur)
- calcAvg()
- if cur > max then max = cur end
- if cur < min or min == 0 then min = cur end
- myGraph:addData(cur)
- myGraph:draw()
- updateScreen()
- cur = 0
- elseif rs.getBundledInput("front") == 3 then
- sleep(0.3)
- test()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement