Advertisement
Guest User

meteor2

a guest
Dec 17th, 2014
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. local signals = {}
  2. local mon = peripheral.wrap("monitor_0")
  3.  
  4. local lastsignal = -1
  5. local peak = -1
  6. local mark = -1
  7. local xMax = -1
  8. local yMax = -1
  9.  
  10. mon.setTextScale(0.5)
  11. xMax, yMax = mon.getSize()
  12.  
  13. local maxsignals = xMax - 2
  14. local maxheight = yMax - 4
  15. local bar = ""
  16.  
  17. for i = 1,maxsignals do bar = bar .. "-" end
  18.  
  19. function drawScreen()
  20.   mon.clear()
  21.  
  22.   local curColor = colors.white
  23.  
  24.   mon.setTextColor(curColor)
  25.  
  26.   for i,s in pairs(signals) do
  27.     xs = maxsignals - i + 2
  28.     ys = math.floor((maxheight * (15 - s) + 8) / 15)
  29.    
  30.     clr = curColor
  31.     if s >= 14 then
  32.       clr = colors.red
  33.     elseif s >= 10 then
  34.       clr = colors.yellow
  35.     elseif s >= 5 then
  36.       clr = colors.green
  37.     else
  38.       clr = colors.white
  39.     end
  40.    
  41.     if clr ~= curColor then
  42.       mon.setTextColor(clr)
  43.       curColor = clr
  44.     end
  45.    
  46.     for y = ys,maxheight do
  47.       mon.setCursorPos(xs,y + 3)
  48.       mon.write("|")
  49.     end
  50.     mon.setCursorPos(xs,ys + 3)
  51.     mon.write(".")
  52.   end
  53.  
  54.   mon.setTextColor(colors.lightBlue)
  55.   mon.setCursorPos(2,2)
  56.   mon.write(bar)
  57.   mon.setCursorPos(2,yMax-1)
  58.   mon.write(bar)
  59.  
  60. end
  61.  
  62. function addSignal(s)
  63.   table.insert(signals,1,s)
  64.   -- Keep the size of the table limite
  65.   if table.getn(signals) > maxsignals then
  66.     table.remove(signals)
  67.   end
  68. end
  69.  
  70. --for i = 0,15 do addSignal(i) end
  71. drawScreen()
  72.  
  73. mark = os.clock() + 60
  74.  
  75. while true do
  76.   signal = rs.getAnalogInput("top")
  77.  
  78.   if signal ~= lastsignal then
  79.     if signal > 10 then
  80.       print("Meteor Signal: "..signal.." at "..os.day().." "..os.time())
  81.     end
  82.  
  83.     if signal < lastsignal then
  84.       -- Meteor hit so it drops to 0
  85.       print("Meteor Detected! "..os.day().." "..os.time())
  86.       peak = 15
  87.       mark = -1
  88.      
  89.     elseif signal > peak then
  90.       peak = signal
  91.     end
  92.  
  93.     lastsignal = signal
  94.   end
  95.  
  96.   if mark <= os.clock() then
  97.     if peak >= 0 then
  98.       addSignal(peak)
  99.     end
  100.     peak = signal
  101.     drawScreen()
  102.     mark = os.clock() + 60
  103.   end
  104.  
  105. --  addSignal(signal)
  106. --  drawScreen()
  107.   sleep(10)
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement