Advertisement
mazenh

Base Control system

Mar 9th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.52 KB | None | 0 0
  1. ----------------------------------(Setup)
  2. mon = peripheral.wrap("Top")
  3.  
  4. ---colors
  5. bg=colors.black  --background
  6. bo=colors.lightBlue  --boarders
  7. txt=colors.blue --default text
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. ----------------------------------(Functions)
  15.     ------------------------[Passive]
  16.         --------------{Clear}
  17.         function mClear(bg1)
  18.             mon.setBackgroundColor(bg1)     --to change clear background color
  19.             mon.clear()
  20.         end
  21.         --------------{Boarder}
  22.         function mBoarder(bg2,txt2)    
  23.             for i=1,51 do
  24.                 mon.setTextColor(txt2)
  25.                 mon.setBackgroundColor(bg2)    --to change boarder color
  26.                 mon.setCursorPos(i,1)
  27.                 mon.write("-")
  28.                 mon.setCursorPos(i,6)
  29.                 mon.write("-")
  30.                 mon.setCursorPos(i,19)
  31.                 mon.write("-")
  32.                 if i<20 then
  33.                     mon.setCursorPos(1,i)
  34.                     mon.write("|")
  35.                     mon.setCursorPos(25,i+5)
  36.                     mon.write("||")
  37.                     mon.setCursorPos(50,i)
  38.                     mon.write("|")
  39.                 end
  40.             end
  41.                
  42.         end
  43.         --------------{Header}
  44.         --Coming Soon
  45.  
  46.  
  47.  
  48.         --------------{fields}
  49.         function mfields(bg3,txt3)
  50.            
  51.             F={"Rubber Farm    ","Steel Generator","Mob Grinder    ","Laser Drills   ","UU Generator  ","Lag Limiter","Base Entrances","Empty Field   8","Empty Field   9","Empty Field  10"}  --15 chars each
  52.            
  53.             j=2
  54.             f=6
  55.             for i=1,8 do
  56.                 if i<6 then j=2 f=6 else j=27 f=-4 end
  57.                 mon.setBackgroundColor(bg3)    --to change background color
  58.                 mon.setTextColor(txt3)
  59.            
  60.                 mon.setCursorPos(j,i*2+f)
  61.                 mon.write("  ")
  62.                 mon.write(F[i])
  63.             end
  64.         end
  65.         --------------{fields status}
  66.        
  67.         function mStatus(bg4)
  68.            
  69.             B1=redstone.getBundledInput("bottom")
  70.            
  71.             for i=1,8 do
  72.                 if i<6 then j=2 f=6 else j=27 f=-4 end
  73.                 mon.setCursorPos(j+18,i*2+f)
  74.  
  75.                 bool1 = bit32.extract(B1,i+7)
  76.                            
  77.                     if bool1==1 then
  78.                         mon.setBackgroundColor(colors.green)    --to change background color
  79.                         mon.setTextColor(bg4)
  80.                         mon.write("ON ")
  81.                     else
  82.                         mon.setBackgroundColor(colors.red)    --to change background color
  83.                         mon.setTextColor(bg4)
  84.                         mon.write("OFF")
  85.                     end
  86.             end
  87.         end
  88.  
  89.  
  90.  
  91.     ------------------------[Active]
  92.         --------------{touchPos}
  93.         function touchPos()  --returns 0-7
  94.  
  95.  
  96. local Y=0
  97. local X=0
  98.  
  99.  
  100.             --A,side,X,Y = os.pullEvent("monitor_touch")
  101.  
  102.  
  103.  
  104. local eventtocatch = 'monitor_touch' --(for example)
  105. local timeout = os.startTimer(2)
  106. local A,side,X1,Y1 = os.pullEvent()
  107. write(A)
  108. print(side)
  109. if A=='timer' and side==timeout then
  110. Y=0
  111. X=0
  112. elseif A==eventtocatch then
  113. X=X1
  114. Y=Y1
  115. end
  116.  
  117.  
  118.  
  119.  
  120.             --temp
  121.             write("(")
  122.             write(X)
  123.             write(",")
  124.             write(Y)
  125.             write(")")
  126.  
  127.        
  128.             if (X <= 22 and X >= 20 and Y == 8) then return(0)
  129.             elseif (X <= 22 and X >= 20 and Y == 10) then return(1)
  130.             elseif (X <= 22 and X >= 20 and Y == 12) then return(2)
  131.             elseif (X <= 22 and X >= 20 and Y == 14) then return(3)
  132.             elseif (X <= 22 and X >= 20 and Y == 16) then return(4)
  133.             elseif (X <= 47 and X >= 45 and Y == 8) then return(5)
  134.             elseif (X <= 47 and X >= 45 and Y == 10) then return(6)
  135.             elseif (X <= 47 and X >= 45 and Y == 12) then return(7)
  136.             else return(-1)
  137.             end
  138.  
  139.         end
  140.         ---------------{toggle}
  141.         function toggle(pos)
  142.  
  143.             if pos >=0 then
  144.             redstone.setBundledOutput("bottom",2^pos)
  145.             os.sleep(0.05)
  146.             redstone.setBundledOutput("bottom",0)
  147.  
  148.             end
  149.         end
  150.  
  151. ---------------------------------(Main Loop)
  152. while true do
  153.  
  154.     mClear(bg)
  155.     mBoarder(bo,txt)
  156.     mfields(bg,txt)
  157.     mStatus(bg)
  158.     pos=touchPos()
  159.     write(pos)                             --temp
  160.     toggle(pos)
  161.     os.sleep(0.15)
  162.     mStatus(bg)
  163. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement