pepeknamornik

client_elektromer

Sep 4th, 2020 (edited)
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.39 KB | None | 0 0
  1. watty = 0.200
  2. local monitor = peripheral.wrap( "right" )
  3. local ModemPos = "top"
  4. local vstup = "left"
  5. local server = 89
  6. --------------------------------------------------------------------------
  7.  
  8. stav = false
  9. historie = false
  10. dcas = 0
  11. cykl = 0
  12. cas1 = 0
  13. sazba = 4.5
  14. local MyID = os.getComputerID()
  15. modem = peripheral.wrap(ModemPos)
  16. modem.open(MyID)
  17.  
  18. if fs.exists("/stav") then
  19. local f = fs.open("/stav", "r")
  20. suma = tonumber(f.readLine())
  21. cykly = tonumber(f.readLine())
  22. f.close()
  23. else
  24. suma = 0
  25. cykly = 0
  26. end
  27.  
  28. function odeslat()
  29. modem.transmit(tonumber(server),8080,MyID)
  30. modem.transmit(tonumber(server),8081,suma)
  31. end
  32.  
  33. function vypis()
  34. monitor.setTextScale(0.5)
  35. monitor.clear()
  36. monitor.setCursorPos(1,1)
  37. monitor.write("Tar: "..watty.."kW/t")
  38. monitor.setCursorPos(1,3)
  39. monitor.write("+ "..((watty*dcas)).." W")
  40. monitor.setCursorPos(1,5)
  41. monitor.write("Tick: "..dcas)
  42. monitor.setCursorPos(1,7)
  43. monitor.write("Sum: ")
  44.     if (suma<1000) then
  45.         monitor.write(suma.." W")
  46.     elseif (suma >= 1000 and suma < 1000000) then
  47.         monitor.write((math.floor(suma/1000)).." kW")
  48.     elseif (suma>= 1000000 and suma <1000000000) then
  49.         monitor.write((math.floor(suma/1000/1000)).." MW")
  50.     elseif (suma>= 1000000000 and suma <1000000000000) then
  51.         monitor.write((math.floor(suma/1000/1000)).." GW")
  52.     elseif (suma>= 1000000000000 and suma <1000000000000000) then
  53.         monitor.write((math.floor(suma/1000/1000)).." TW")
  54.     end
  55. monitor.setCursorPos(1,9)
  56. monitor.write("Cena: "..(math.floor(suma/1000*sazba)).."MC")
  57. end
  58.  
  59. function vypocet()
  60.     suma = math.floor((suma +watty*dcas)*100)
  61.     suma = suma/100
  62.     cykly = cykly + 1
  63.     local f = fs.open("/stav", "w")
  64.     f.writeLine(suma)
  65.     f.writeLine(cykly)
  66.     f.close()
  67.     odeslat()
  68.     vypis()
  69. end
  70.  
  71. function loop()
  72.     if (redstone.getInput(vstup)) then
  73.     stav = true
  74.     else
  75.     stav = false
  76.     end
  77.    
  78.    
  79.     if not (historie == stav) then
  80.         if stav then
  81.         cas1 = (os.time() * 1000 + 18000)%24000
  82.         else
  83.         cas2 = (os.time() * 1000 + 18000)%24000
  84.         dcas = cas2-cas1
  85.         if (dcas<0) then dcas = 0 end
  86.         vypocet()
  87.         end
  88.     historie = stav
  89.     elseif cykl == 99 and stav then
  90.     cas2 = (os.time() * 1000 + 18000)%24000
  91.         dcas = cas2-cas1
  92.         if (dcas<0) then dcas = 0 end
  93.         vypocet()
  94.     cas1 = (os.time() * 1000 + 18000)%24000
  95.     print (dcas)
  96.     sleep(1)
  97.     end
  98.    
  99.     cykl = cykl+1
  100.     if (cykl >= 100) then os.reboot() end
  101.     sleep (0.1)
  102.     loop()
  103. end
  104. term.clear()
  105. term.write(tostring(MyID))
  106. loop()
  107.  
Add Comment
Please, Sign In to add comment