SHOW:
         |
         |
         - or go back to the newest paste.    
    | 1 | os.loadAPI("button")
 | |
| 2 | ||
| 3 | p = peripheral.find("tile_blockcapacitorbank_name")
 | |
| 4 | m = peripheral.find("monitor")
 | |
| 5 | r = peripheral.find("BigReactors-Reactor")
 | |
| 6 | t = peripheral.find("BigReactors-Turbine")
 | |
| 7 | ||
| 8 | local steamReactor = r.isActivelyCooled()  | |
| 9 | local menuType = "Reactor"  | |
| 10 | ||
| 11 | local numCapacitors = 3  | |
| 12 | local turnOnAt = 50  | |
| 13 | local turnOffAt = 90  | |
| 14 | ||
| 15 | local targetSpeed = 1840  | |
| 16 | ||
| 17 | local energy = 0  | |
| 18 | local energyStored = 0  | |
| 19 | local energyMax = 0  | |
| 20 | local energyStoredPercent = 0  | |
| 21 | local timerCode  | |
| 22 | local mode = "Automatic"  | |
| 23 | local RFProduction = 0  | |
| 24 | local fuelUse = 0  | |
| 25 | local coreTemp = 0  | |
| 26 | local reactorOnline = false  | |
| 27 | local rodLevel = 0  | |
| 28 | ||
| 29 | local turbineOnline = false  | |
| 30 | local turbineRotorSpeed = 0  | |
| 31 | local turbineRFGen = 0  | |
| 32 | local turbineFluidRate = 0  | |
| 33 | local turbineInductor = false  | |
| 34 | ||
| 35 | local OptFuelRodLevel = 0  | |
| 36 | ||
| 37 | function autoMenu()  | |
| 38 | m.setTextScale(1)  | |
| 39 | button.clearTable()  | |
| 40 |    button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
 | |
| 41 |    button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
 | |
| 42 | ||
| 43 | if steamReactor then  | |
| 44 |       button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
 | |
| 45 |       button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
 | |
| 46 | end  | |
| 47 | button.screen()  | |
| 48 | checkMode()  | |
| 49 | menuMode()  | |
| 50 | end  | |
| 51 | ||
| 52 | function manualMenu()  | |
| 53 | m.setTextScale(1)  | |
| 54 | button.clearTable()  | |
| 55 |    button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
 | |
| 56 |    button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
 | |
| 57 |    button.setTable("Online", online, "", 3, 13, 8, 8)
 | |
| 58 |    button.setTable("Offline", offline, "", 15, 25, 8, 8)
 | |
| 59 |    button.setTable("0", setRods, 0, 11,14, 10, 10)
 | |
| 60 |    button.setTable("10", setRods, 10, 5,8, 12, 12)
 | |
| 61 |    button.setTable("20", setRods, 20, 11,14, 12, 12)
 | |
| 62 |    button.setTable("30", setRods, 30, 17,20, 12, 12)
 | |
| 63 |    button.setTable("40", setRods, 40, 5,8, 14, 14)
 | |
| 64 |    button.setTable("50", setRods, 50, 11,14, 14, 14)
 | |
| 65 |    button.setTable("60", setRods, 60, 17,20, 14, 14)
 | |
| 66 |    button.setTable("70", setRods, 70, 5,8, 16, 16)
 | |
| 67 |    button.setTable("80", setRods, 80, 11,14, 16, 16)
 | |
| 68 |    button.setTable("90", setRods, 90, 17,20, 16, 16)
 | |
| 69 |    button.setTable("+", rodPlus, "", 23, 25, 12, 12)
 | |
| 70 |    button.setTable("-", rodMinus, "", 23, 25, 16, 16) 
 | |
| 71 | ||
| 72 | if steamReactor then  | |
| 73 |       button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
 | |
| 74 |       button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
 | |
| 75 | ||
| 76 | end  | |
| 77 | button.screen()  | |
| 78 | checkMode()  | |
| 79 | reactorOnOff()  | |
| 80 | menuMode()  | |
| 81 | end  | |
| 82 | ||
| 83 | function turbineAutoMenu()  | |
| 84 | m.setTextScale(1)  | |
| 85 | button.clearTable()  | |
| 86 |    button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
 | |
| 87 |    button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
 | |
| 88 |    button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
 | |
| 89 |    button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
 | |
| 90 | button.screen()  | |
| 91 | checkMode()  | |
| 92 | menuMode()  | |
| 93 | end  | |
| 94 | ||
| 95 | function turbineManualMenu()  | |
| 96 | m.setTextScale(1)  | |
| 97 | button.clearTable()  | |
| 98 |    button.setTable("Automatic", autoMode, "", 3, 13, 6, 6)
 | |
| 99 |    button.setTable("Manual", manualMode, "", 15, 25, 6, 6)
 | |
| 100 |    button.setTable("Reactor", reactorMenu, "", 5, 18, 19, 19)
 | |
| 101 |    button.setTable("Turbine", turbineMenu, "", 22, 35, 19, 19)
 | |
| 102 |    button.setTable("Online", setTurbineOnline, "", 3, 13, 8, 8)
 | |
| 103 |    button.setTable("Offline", setTurbineOffline, "", 15, 25, 8, 8)
 | |
| 104 |    button.setTable("Coils On", coilsOn, "", 3, 13, 10, 10)
 | |
| 105 |    button.setTable("Coils Off", coilsOff, "", 15, 25, 10, 10)
 | |
| 106 | button.screen()  | |
| 107 | checkMode()  | |
| 108 | turbineOnOff()  | |
| 109 | coilsOnOff()  | |
| 110 | menuMode()  | |
| 111 | end  | |
| 112 | ||
| 113 | function reactorMenu()  | |
| 114 | menuType = "Reactor"  | |
| 115 | displayScreen()  | |
| 116 | end  | |
| 117 | ||
| 118 | function turbineMenu()  | |
| 119 | menuType = "Turbine"  | |
| 120 | displayScreen()  | |
| 121 | end  | |
| 122 | ||
| 123 | function online()  | |
| 124 | r.setActive(true)  | |
| 125 |    --button.flash("Online")
 | |
| 126 | end  | |
| 127 | ||
| 128 | function offline()  | |
| 129 | r.setActive(false)  | |
| 130 |    --button.flash("Offline")
 | |
| 131 | end  | |
| 132 | ||
| 133 | function setTurbineOnline()  | |
| 134 | t.setActive(true)  | |
| 135 |    --button.flash("Online")
 | |
| 136 | end  | |
| 137 | ||
| 138 | function setTurbineOffline()  | |
| 139 | t.setActive(false)  | |
| 140 |    --button.flash("Offline")
 | |
| 141 | end  | |
| 142 | ||
| 143 | function reactorOnOff()  | |
| 144 |    button.setButton("Online", r.getActive())
 | |
| 145 |    button.setButton("Offline", not r.getActive())
 | |
| 146 | end  | |
| 147 | ||
| 148 | function turbineOnOff()  | |
| 149 |    button.setButton("Online", t.getActive())
 | |
| 150 |    button.setButton("Offline", not t.getActive())
 | |
| 151 | end  | |
| 152 | ||
| 153 | function coilsOnOff()  | |
| 154 |    button.setButton("Coils On", t.getInductorEngaged())
 | |
| 155 |    button.setButton("Coils Off", not t.getInductorEngaged())
 | |
| 156 | end  | |
| 157 | ||
| 158 | function coilsOn()  | |
| 159 | t.setInductorEngaged(true)  | |
| 160 | end  | |
| 161 | ||
| 162 | function coilsOff()  | |
| 163 | t.setInductorEngaged(false)  | |
| 164 | end  | |
| 165 | ||
| 166 | function menuMode()  | |
| 167 | if steamReactor then  | |
| 168 | if menuType == "Reactor" then  | |
| 169 |      button.setButton("Reactor", true)
 | |
| 170 |      button.setButton("Turbine", false)
 | |
| 171 | else  | |
| 172 |      button.setButton("Reactor", false)
 | |
| 173 |      button.setButton("Turbine", true)
 | |
| 174 | end  | |
| 175 | end  | |
| 176 | end  | |
| 177 | ||
| 178 | function setRods(setLevel)  | |
| 179 |    print("Setting Rod Level: "..setLevel)
 | |
| 180 | button.flash(tostring(setLevel))  | |
| 181 | r.setAllControlRodLevels(setLevel)  | |
| 182 | fuelRodLevel()  | |
| 183 | end  | |
| 184 | ||
| 185 | function rodPlus()  | |
| 186 |    button.flash("+")
 | |
| 187 | r.setAllControlRodLevels(rodLevel+1)  | |
| 188 | fuelRodLevel()  | |
| 189 | end  | |
| 190 | ||
| 191 | function rodMinus()  | |
| 192 |    button.flash("-")
 | |
| 193 | r.setAllControlRodLevels(rodLevel-1)  | |
| 194 | fuelRodLevel()  | |
| 195 | end  | |
| 196 | ||
| 197 | function checkMode()  | |
| 198 | button.toggleButton(mode)  | |
| 199 | end  | |
| 200 | ||
| 201 | function manualMode()  | |
| 202 | mode = "Manual"  | |
| 203 | manualMenu()  | |
| 204 | end  | |
| 205 | ||
| 206 | function autoMode()  | |
| 207 | mode = "Automatic"  | |
| 208 | displayScreen()  | |
| 209 | end  | |
| 210 | ||
| 211 | function comma_value(amount)  | |
| 212 | local formatted = amount  | |
| 213 | local swap = false  | |
| 214 | if formatted < 0 then  | |
| 215 | formatted = formatted*-1  | |
| 216 | swap = true  | |
| 217 | end  | |
| 218 | while true do  | |
| 219 | formatted, k = string.gsub(formatted, "^(%d+)(%d%d%d)", '%1,%2')  | |
| 220 | if k == 0 then  | |
| 221 | break  | |
| 222 | end  | |
| 223 | end  | |
| 224 | if swap then  | |
| 225 | formatted = "-"..formatted  | |
| 226 | end  | |
| 227 | return formatted  | |
| 228 | end  | |
| 229 | ||
| 230 | function displayEn()  | |
| 231 | m.clear()  | |
| 232 | m.setCursorPos(1,1)  | |
| 233 |    --print("Energy Use: "..energy)
 | |
| 234 |    m.write("Energy Use: ")
 | |
| 235 | if energy < 0 then  | |
| 236 | m.setTextColor(colors.red)  | |
| 237 | else  | |
| 238 | m.setTextColor(colors.green)  | |
| 239 | end  | |
| 240 | m.write(comma_value(math.floor(energy)).. "RF/t")  | |
| 241 | m.setTextColor(colors.white)  | |
| 242 | m.setCursorPos(1,2)  | |
| 243 |    m.write("Energy Stored: "..energyStoredPercent.."%")
 | |
| 244 | if menuType == "Reactor" then  | |
| 245 | m.setCursorPos(1,3)  | |
| 246 |       m.write("Reactor is: ")
 | |
| 247 | if reactorOnline then  | |
| 248 | m.setTextColor(colors.green)  | |
| 249 | 	   m.write("Online")
 | |
| 250 | else  | |
| 251 | m.setTextColor(colors.red)  | |
| 252 | 	   m.write("Offline")
 | |
| 253 | end  | |
| 254 | m.setTextColor(colors.white)  | |
| 255 | m.setCursorPos(22,1)  | |
| 256 | if steamReactor then  | |
| 257 |          m.write("Steam: ")
 | |
| 258 | m.setTextColor(colors.green)  | |
| 259 | m.write(comma_value(math.floor(RFProduction)).."MB/t")  | |
| 260 | else  | |
| 261 |          m.write("RF Gen: ")
 | |
| 262 | m.setTextColor(colors.green)  | |
| 263 | m.write(comma_value(math.floor(RFProduction)).."RF/t")  | |
| 264 | end  | |
| 265 | m.setTextColor(colors.white)  | |
| 266 | m.setCursorPos(22,2)  | |
| 267 |       m.write("Core Temp: "..math.floor(coreTemp).."c")
 | |
| 268 | m.setCursorPos(22,3)  | |
| 269 |       m.write("Fuel Use: "..fuelUse.."MB/t")  
 | |
| 270 | else  | |
| 271 | m.setCursorPos(1,3)  | |
| 272 |       m.write("Turbine is: ")
 | |
| 273 | if turbineOnline then  | |
| 274 | m.setTextColor(colors.green)  | |
| 275 | 	   m.write("Online")
 | |
| 276 | else  | |
| 277 | m.setTextColor(colors.red)  | |
| 278 | 	   m.write("Offline")
 | |
| 279 | end  | |
| 280 | m.setCursorPos(1,4)  | |
| 281 | m.setTextColor(colors.white)  | |
| 282 |       m.write("Reactor is: ")
 | |
| 283 | if reactorOnline then  | |
| 284 | m.setTextColor(colors.green)  | |
| 285 |          m.write("Online")
 | |
| 286 | else  | |
| 287 | m.setTextColor(colors.red)  | |
| 288 |          m.write("Offline")
 | |
| 289 | end  | |
| 290 | m.setTextColor(colors.white)  | |
| 291 | m.setCursorPos(22,1)  | |
| 292 | 	  m.write("RFGen: ")
 | |
| 293 | m.setTextColor(colors.green)  | |
| 294 | m.write(comma_value(math.floor(turbineRFGen)).."RF/t")  | |
| 295 | m.setTextColor(colors.white)  | |
| 296 | m.setCursorPos(22,2)  | |
| 297 |       m.write("Rotor: "..comma_value(math.floor(turbineRotorSpeed)).." RPM")
 | |
| 298 | m.setCursorPos(22,3)  | |
| 299 |       m.write("Steam: "..comma_value(turbineFluidRate).."MB/t")  
 | |
| 300 | end  | |
| 301 | ||
| 302 | end  | |
| 303 | ||
| 304 | function checkEn()  | |
| 305 | local tempEnergy = 0  | |
| 306 | energyStored = p.getEnergyStored()  | |
| 307 | energyMax = p.getMaxEnergyStored()  | |
| 308 | energyStoredPercent = math.floor((energyStored/energyMax)*100)  | |
| 309 | RFProduction = r.getEnergyProducedLastTick()  | |
| 310 | fuelUse = r.getFuelConsumedLastTick()  | |
| 311 | fuelUse = math.floor(fuelUse*100)  | |
| 312 | fuelUse = fuelUse/100  | |
| 313 | coreTemp = r.getFuelTemperature()  | |
| 314 | reactorOnline = r.getActive()  | |
| 315 | tempEnergy = p.getEnergyStored()  | |
| 316 | sleep(0.1)  | |
| 317 | energy = (p.getEnergyStored()-tempEnergy)/2  | |
| 318 | energy = energy*numCapacitors  | |
| 319 | if steamReactor then  | |
| 320 | turbineOnline = t.getActive()  | |
| 321 | turbineRotorSpeed = t.getRotorSpeed()  | |
| 322 | turbineRFGen = t.getEnergyProducedLastTick()  | |
| 323 | turbineFluidRate = t.getFluidFlowRate()  | |
| 324 | end  | |
| 325 | end  | |
| 326 | ||
| 327 | function fuelRodLevel()  | |
| 328 | rodLevel = r.getControlRodLevel(0)  | |
| 329 | --print(rodLevel)  | |
| 330 | m.setCursorPos(30,5)  | |
| 331 | m.write(tostring(rodLevel).."%")  | |
| 332 | m.setBackgroundColor(colors.white)  | |
| 333 | m.setCursorPos(28,6)  | |
| 334 |    m.write("       ")
 | |
| 335 | for i = 1,10 do  | |
| 336 | m.setCursorPos(28,i+6)  | |
| 337 | m.setBackgroundColor(colors.white)  | |
| 338 | 	  m.write(" ")
 | |
| 339 | m.setBackgroundColor(colors.yellow)  | |
| 340 | 	  m.write(" ")
 | |
| 341 | if rodLevel/10 >= i then  | |
| 342 | m.setBackgroundColor(colors.red)  | |
| 343 | else  | |
| 344 | m.setBackgroundColor(colors.yellow)  | |
| 345 | end  | |
| 346 | 	  m.write("   ")
 | |
| 347 | m.setBackgroundColor(colors.yellow)  | |
| 348 | 	  m.write(" ")
 | |
| 349 | m.setBackgroundColor(colors.white)  | |
| 350 | 	  m.write(" ")
 | |
| 351 | end  | |
| 352 | m.setCursorPos(28,17)  | |
| 353 |    m.write("       ")
 | |
| 354 | m.setBackgroundColor(colors.black)  | |
| 355 | end  | |
| 356 | ||
| 357 | function turbineInductorDisplay()  | |
| 358 | turbineInductor = t.getInductorEngaged()  | |
| 359 | m.setCursorPos(30,5)  | |
| 360 | if turbineInductor then  | |
| 361 |       m.write("On")
 | |
| 362 | else  | |
| 363 |       m.write("Off")
 | |
| 364 | end  | |
| 365 | m.setBackgroundColor(colors.gray)  | |
| 366 | m.setCursorPos(28,6)  | |
| 367 |    m.write("       ")
 | |
| 368 | for i = 1,7 do  | |
| 369 | m.setCursorPos(28,i+6)  | |
| 370 | m.setBackgroundColor(colors.gray)  | |
| 371 | 	  m.write(" ")
 | |
| 372 | m.setBackgroundColor(colors.lightGray)  | |
| 373 | 	  m.write(" ")
 | |
| 374 | if i % 2 == 0 then  | |
| 375 | m.setBackgroundColor(colors.gray)  | |
| 376 | end  | |
| 377 | 	  m.write(" ")
 | |
| 378 | m.setBackgroundColor(colors.gray)  | |
| 379 | 	  m.write(" ")
 | |
| 380 | if i % 2 ~= 0 then  | |
| 381 | m.setBackgroundColor(colors.lightGray)  | |
| 382 | end  | |
| 383 | 	  m.write(" ")
 | |
| 384 | m.setBackgroundColor(colors.lightGray)  | |
| 385 | 	  m.write(" ")
 | |
| 386 | m.setBackgroundColor(colors.gray)  | |
| 387 | 	  m.write(" ")
 | |
| 388 | end  | |
| 389 | for i = 8,10 do  | |
| 390 | m.setCursorPos(28,i+6)  | |
| 391 | m.setBackgroundColor(colors.gray)  | |
| 392 | 	  m.write(" ")
 | |
| 393 | m.setBackgroundColor(colors.lightGray)  | |
| 394 | 	  m.write(" ")
 | |
| 395 | if turbineInductor then  | |
| 396 | m.setBackgroundColor(colors.red)  | |
| 397 | else  | |
| 398 | m.setBackgroundColor(colors.blue)  | |
| 399 | end  | |
| 400 | 	  m.write(" ")
 | |
| 401 | m.setBackgroundColor(colors.gray)  | |
| 402 | 	  m.write(" ")
 | |
| 403 | if turbineInductor then  | |
| 404 | m.setBackgroundColor(colors.red)  | |
| 405 | else  | |
| 406 | m.setBackgroundColor(colors.blue)  | |
| 407 | end  | |
| 408 | 	  m.write(" ")
 | |
| 409 | m.setBackgroundColor(colors.lightGray)  | |
| 410 | 	  m.write(" ")
 | |
| 411 | m.setBackgroundColor(colors.gray)  | |
| 412 | 	  m.write(" ")
 | |
| 413 | end  | |
| 414 | m.setCursorPos(28,17)  | |
| 415 |    m.write("       ")
 | |
| 416 | m.setBackgroundColor(colors.black)  | |
| 417 | end  | |
| 418 | function getClick()  | |
| 419 |    local event, side, x, y = os.pullEvent("monitor_touch")
 | |
| 420 | button.checkxy(x,y)  | |
| 421 | end  | |
| 422 | ||
| 423 | function findOptFuelRods()  | |
| 424 | m.clear()  | |
| 425 | r.setActive(false)  | |
| 426 | checkEn()  | |
| 427 | displayEn()  | |
| 428 | fuelRodLevel()  | |
| 429 | while r.getFuelTemperature() > 99 do  | |
| 430 | for i= 1,3 do  | |
| 431 | checkEn()  | |
| 432 | displayEn()  | |
| 433 | fuelRodLevel()  | |
| 434 | m.setCursorPos(3,6)  | |
| 435 |         m.write("Finding Optimal Rod Level")
 | |
| 436 | m.setCursorPos(3,7)  | |
| 437 | 	    m.write("Core Temp: "..r.getFuelTemperature())
 | |
| 438 | m.setCursorPos(3,8)  | |
| 439 | 		m.write("Waiting for 99c")
 | |
| 440 | sleep(1)  | |
| 441 | end  | |
| 442 | end  | |
| 443 | while r.getHotFluidAmount() > 10000 do  | |
| 444 | for i = 1,3 do  | |
| 445 | checkEn()  | |
| 446 | displayEn()  | |
| 447 | fuelRodLevel()  | |
| 448 | m.setCursorPos(3,6)  | |
| 449 |         m.write("Finding Optimal Rod Level, please wait....")
 | |
| 450 | m.setCursorPos(3,7)  | |
| 451 |    	    m.write("Fluid Amount: "..comma_value(r.getHotFluidAmount()).."mb")
 | |
| 452 | m.setCursorPos(3,8)  | |
| 453 | 		m.write("Waiting for 10,000mb")
 | |
| 454 | sleep(1)  | |
| 455 | end  | |
| 456 | end  | |
| 457 | r.setAllControlRodLevels(99)  | |
| 458 | r.setActive(true)  | |
| 459 | ||
| 460 | while r.getFuelTemperature() < 100 do  | |
| 461 | for i = 1,5 do  | |
| 462 | checkEn()  | |
| 463 | displayEn()  | |
| 464 | fuelRodLevel()  | |
| 465 | m.setCursorPos(3,6)  | |
| 466 | 	 m.write("Set all rod levels to 99")
 | |
| 467 | m.setCursorPos(3,7)  | |
| 468 | 	 m.write("Waiting 5 seconds...")
 | |
| 469 | sleep(1)  | |
| 470 | end  | |
| 471 | end  | |
| 472 | for i = 1,5 do  | |
| 473 | checkEn()  | |
| 474 | displayEn()  | |
| 475 | fuelRodLevel()  | |
| 476 | m.setCursorPos(3,6)  | |
| 477 | 	 m.write("Set all rod levels to 99")
 | |
| 478 | m.setCursorPos(3,7)  | |
| 479 | 	 m.write("Waiting 5 seconds...")
 | |
| 480 | sleep(1)  | |
| 481 | end  | |
| 482 | local tempMB = r.getEnergyProducedLastTick()  | |
| 483 | print(tempMB.."MB/t of steam")  | |
| 484 | local tempRodLevels = math.floor(2000/tempMB)  | |
| 485 |    print("2000/"..tempMB.." = "..tempRodLevels)
 | |
| 486 | tempRodLevels = 100-tempRodLevels+5  | |
| 487 |    print("Adding 5 to Rod Levels: "..math.floor(tempRodLevels))
 | |
| 488 | r.setAllControlRodLevels(math.floor(tempRodLevels))  | |
| 489 |    print("Waiting 10 seconds to confirm...")
 | |
| 490 | for i = 1,10 do  | |
| 491 | checkEn()  | |
| 492 | displayEn()  | |
| 493 | fuelRodLevel()  | |
| 494 | m.setCursorPos(3,6)  | |
| 495 | 	 m.write("Estimated Level: "..tempRodLevels)
 | |
| 496 | m.setCursorPos(3,7)  | |
| 497 | 	 m.write("Waiting 10 seconds...")
 | |
| 498 | sleep(1)  | |
| 499 | end  | |
| 500 | tempMB = r.getEnergyProducedLastTick()  | |
| 501 | while tempMB > 2000 do  | |
| 502 | tempRodLevels = tempRodLevels+1  | |
| 503 | r.setAllControlRodLevels(math.floor(tempRodLevels))  | |
| 504 | 	  print("Setting Rod Levels to: "..tempRodLevels)
 | |
| 505 | for i = 1,5 do  | |
| 506 | checkEn()  | |
| 507 | displayEn()  | |
| 508 | fuelRodLevel()  | |
| 509 | m.setCursorPos(3,6)  | |
| 510 |        m.write("Getting below 2000mb/t")
 | |
| 511 | m.setCursorPos(3,7)  | |
| 512 | 	   m.write("Currently at: "..tempMB)
 | |
| 513 | sleep(1)  | |
| 514 | end  | |
| 515 | tempMB = r.getEnergyProducedLastTick()  | |
| 516 | end  | |
| 517 | while tempMB < 2000 do  | |
| 518 | tempRodLevels = tempRodLevels -1  | |
| 519 | r.setAllControlRodLevels(math.floor(tempRodLevels))  | |
| 520 | 	  print("Setting Rod Levels to: "..tempRodLevels)
 | |
| 521 | for i = 1,5 do  | |
| 522 | checkEn()  | |
| 523 | displayEn()  | |
| 524 | fuelRodLevel()  | |
| 525 | m.setCursorPos(3,6)  | |
| 526 | 	   m.write("Getting Above 2000mb/t")
 | |
| 527 | m.setCursorPos(3,7)  | |
| 528 | 	   m.write("Currently at: "..tempMB)
 | |
| 529 | sleep(1)  | |
| 530 | end  | |
| 531 | tempMB = r.getEnergyProducedLastTick()  | |
| 532 | end  | |
| 533 | OptFuelRodLevel = tempRodLevels  | |
| 534 | end  | |
| 535 | ||
| 536 | ||
| 537 | function autoReactor()  | |
| 538 | if not steamReactor then  | |
| 539 | r.setAllControlRodLevels(0)  | |
| 540 | if energyStoredPercent < turnOnAt then  | |
| 541 | if not reactorOnline then  | |
| 542 | online()  | |
| 543 | end  | |
| 544 | end  | |
| 545 | if energyStoredPercent > turnOffAt then  | |
| 546 | if reactorOnline then  | |
| 547 | offline()  | |
| 548 | end  | |
| 549 | end  | |
| 550 | else  | |
| 551 | r.setAllControlRodLevels(OptFuelRodLevel)  | |
| 552 | if energyStoredPercent < turnOnAt then  | |
| 553 | --online()  | |
| 554 | setTurbineOnline()  | |
| 555 | coilsOn()  | |
| 556 | end  | |
| 557 | if energyStoredPercent > turnOffAt then  | |
| 558 | --if turbineRotorSpeed > 1800 then  | |
| 559 | -- offline()  | |
| 560 | --else  | |
| 561 | -- online()  | |
| 562 | --end  | |
| 563 | setTurbineOnline()  | |
| 564 | coilsOff()  | |
| 565 | end  | |
| 566 | if turbineRotorSpeed > targetSpeed then  | |
| 567 | offline()  | |
| 568 | else  | |
| 569 | online()  | |
| 570 | end  | |
| 571 | end  | |
| 572 | end  | |
| 573 | ||
| 574 | function displayScreen()  | |
| 575 | -- repeat  | |
| 576 | checkEn()  | |
| 577 | displayEn()  | |
| 578 | if menuType == "Reactor" then  | |
| 579 | fuelRodLevel()  | |
| 580 | if mode == "Automatic" then  | |
| 581 | autoMenu()  | |
| 582 | autoReactor()  | |
| 583 | else  | |
| 584 | manualMenu()  | |
| 585 | end  | |
| 586 | ||
| 587 | else  | |
| 588 | turbineInductorDisplay()  | |
| 589 | if mode == "Automatic" then  | |
| 590 | turbineAutoMenu()  | |
| 591 | autoReactor()  | |
| 592 | else  | |
| 593 | turbineManualMenu()  | |
| 594 | end  | |
| 595 | ||
| 596 | end  | |
| 597 | ||
| 598 | timerCode = os.startTimer(1)  | |
| 599 | local event, side, x, y  | |
| 600 | repeat  | |
| 601 | event, side, x, y = os.pullEvent()  | |
| 602 | print(event)  | |
| 603 | if event == "timer" then  | |
| 604 | print(timerCode..":"..side)  | |
| 605 | if timerCode ~= side then  | |
| 606 | 		      print("Wrong Code")
 | |
| 607 | else  | |
| 608 | 			  print("Right Code")
 | |
| 609 | end  | |
| 610 | end  | |
| 611 | until event~= "timer" or timerCode == side  | |
| 612 | if event == "monitor_touch" then  | |
| 613 | print(x..":"..y)  | |
| 614 | button.checkxy(x,y)  | |
| 615 | end  | |
| 616 | -- until event ~= "timer"  | |
| 617 | end  | |
| 618 | ||
| 619 | if steamReactor then  | |
| 620 | findOptFuelRods()  | |
| 621 | end  | |
| 622 | ||
| 623 | while true do  | |
| 624 | displayScreen()  | |
| 625 | end  |