largeNumberGoeshere

CC nixie fluid readout

Mar 3rd, 2025 (edited)
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1.  
  2. print("Printing tank fullness to nixie tubes")
  3. local prevTankPercent = -1  -- the tank doesn't seem to show up when no updates are given
  4. local blinkFlag = false
  5. while true do
  6.     local tank = peripheral.find("modern_industrialization:large_tank_hatch")
  7.     local display = peripheral.find("create_source")
  8.  
  9.     local percentage = -1
  10.     local tanks = tank.tanks()
  11.    
  12.     if #tanks > 0 or tanks[1] ~= nil then
  13.         local amount = tanks[1].amount
  14.         local capacity = tanks[1].capacity
  15.         local ratio = amount / capacity
  16.         percentage = ratio *100
  17.  
  18.         print(tostring(os.time()).."new data")
  19.     else
  20.         print(tostring(os.time()) .. "outdated info")  
  21.         percentage = prevTankPercent
  22.     end
  23.  
  24.     local outstr = ""
  25.  
  26.    
  27.     if percentage == -1 then
  28.         outstr = outstr .. " ??.??%"
  29.        
  30.         print(tostring(os.time()) .. "no data")
  31.     elseif percentage == 1 then
  32.         outstr = outstr .. "100.00%" .. " "
  33.     else
  34.         local dig_0 = math.floor((percentage / 10) % 10)
  35.         local dig_1 = math.floor(percentage % 10)
  36.         local dig_2 = math.floor((percentage *10) %10)
  37.         local dig_3 = math.floor((percentage *100) %10)
  38.        
  39.         outstr = outstr .. " " .. tostring(dig_0) .. tostring(dig_1) .. "." .. tostring(dig_2) .. tostring(dig_3) .. "%" .. " "
  40.     end
  41.    
  42.     if blinkFlag == true then
  43.         if (percentage > prevTankPercent) then
  44.             outstr = outstr .. "^"
  45.         elseif (percentage < prevTankPercent) then
  46.             outstr = outstr .. "v"
  47.         else
  48.             outstr = outstr .. " " 
  49.         end
  50.     end
  51.    
  52.     display.clear()
  53.     display.setCursorPos(1,1)  
  54.     display.write(outstr)
  55.    
  56.     prevTankPercent = percentage
  57.     blinkFlag = not blinkFlag
  58.     sleep(1)    
  59. end
Advertisement
Add Comment
Please, Sign In to add comment