Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- next step colors the tracks
- --Train Control--
- --works with cable server--
- -- MONITOR was CHANGED in monitor.cfg--
- --optimal monitor size 5*4--
- --config--
- local channel = 31
- local backchan = 32
- local col = colors.white
- modem = peripheral.wrap("back")
- --var----
- local mon = ""
- local power = true
- --set monitor
- function set_monitor()
- local monitor_number = "monitor_1"
- local found = fs.exists("config/monitor.cfg")
- if found == true then
- file = fs.open("config/monitor.cfg","r")
- local fileData = {}
- local line = file.readLine()
- repeat
- table.insert(fileData,line)
- line = file.readLine()
- until line == nil
- file.close()
- monitor_number = fileData[1]
- end
- mon = peripheral.wrap(monitor_number)
- end
- -- draw screen --
- function draw_screen()
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- mon.clear()
- mon.setBackgroundColor(colors.black)
- mon.setCursorPos(1,1)
- mon.setBackgroundColor(colors.blue)
- mon.write("Train Control Channel:"..channel.." ")
- mon.setCursorPos(50,1)
- mon.setBackgroundColor(colors.red)
- mon.setTextColor(colors.black)
- mon.write("X")
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- mon.setCursorPos(25,2)
- mon.write("Track 11")
- mon.setCursorPos(25,4)
- mon.write("Track 10")
- mon.setCursorPos(25,6)
- mon.write("Track 9")
- mon.setCursorPos(25,8)
- mon.write("Track 8")
- mon.setCursorPos(25,10)
- mon.write("Track 7")
- mon.setCursorPos(25,12)
- mon.write("Track 6")
- mon.setCursorPos(25,15)
- mon.write("Track 5")
- mon.setCursorPos(25,17)
- mon.write("Track 4")
- mon.setCursorPos(25,19)
- mon.write("Track 3")
- mon.setCursorPos(25,21)
- mon.write("Track 2")
- mon.setCursorPos(25,23)
- mon.write("Track 1")
- mon.setCursorPos(1,21)
- mon.write("Track 13")
- mon.setCursorPos(1,23)
- mon.write("Track 14")
- --draw button
- draw_button(20,4,3)
- draw_button(20,6,3)
- draw_button(20,8,3)
- draw_button(20,10,3)
- draw_button(20,12,3)
- draw_button(20,19,3)
- draw_button(20,21,3)
- draw_button(20,23,3)--1
- draw_button(10,21,3)--13
- draw_button(10,23,3)--14
- draw_button(3,15,3) --left ran.
- draw_button(44,15,3) --right ran.
- draw_button(1,17,3) --left 4to5
- draw_button(8,17,3) --left 5to4
- draw_button(42,17,3) --right 4to5
- draw_button(49,17,3) --right 5to4
- --draw track
- if rs.testBundledInput("left", colors.red) then
- col = colors.green
- else
- col = colors.white
- end
- draw_line(8,3,34,col)
- if rs.testBundledInput("left", colors.green) then
- col = colors.green
- else
- col = colors.white
- end
- draw_line(9,5,32,col)
- draw_switch(41,6,"|",col)
- draw_switch(8,6,"/",col)
- if rs.testBundledInput("left", colors.brown) then
- col = colors.green
- else
- col = colors.white
- end
- draw_line(9,7,32,col)
- draw_switch(41,8,"|",col)
- draw_switch(8,8,"/",col)
- if rs.testBundledInput("left", colors.blue) then
- col = colors.green
- else
- col = colors.white
- end
- draw_line(9,9,32,col)
- draw_switch(41,10,"|",col)
- draw_switch(8,10,"/",col)
- if rs.testBundledInput("left", colors.purple) then
- col = colors.green
- else
- col = colors.white
- end
- draw_line(9,11,32,col)
- draw_switch(41,12,"|",col)
- draw_switch(8,12,"/",col)
- if rs.testBundledInput("left", colors.cyan) then
- col = colors.green
- else
- col = colors.white
- end
- draw_line(9,13,32,col)
- draw_switch(41,14,"|",col)
- draw_switch(8,14,"/",col)
- col = colors.green
- draw_line(1,16,50,col)
- draw_line(1,18,50,col)
- if rs.testBundledInput("left", colors.lightGray) then
- col = colors.green
- else
- col = colors.white
- end
- draw_line(19,20,28,col)
- draw_switch(47,19,"/",col)
- draw_switch(18,20,"|",col)
- if rs.testBundledInput("left", colors.yellow) then
- col = colors.green
- else
- col = colors.white
- end
- draw_line(16,22,24,col)
- draw_column(16,18,5,col)
- draw_column(39,18,5,col)
- draw_switch(15,17,"|",col)
- draw_switch(40,17,"/",col)
- if rs.testBundledInput("left", colors.lime) then
- col = colors.green
- else
- col = colors.white
- end
- draw_line(14,24,28,col)
- draw_switch(13,19,"|",col)
- draw_switch(43,19,"/",col)
- draw_column(14,20,5,col)
- draw_column(42,20,5,col)
- if rs.testBundledInput("left", colors.lightBlue) then
- col = colors.green
- else
- col = colors.white
- end
- draw_line(2,22,7,col)
- draw_switch(1,22,"|",col)
- if rs.testBundledInput("left", colors.magenta) then
- col = colors.green
- else
- col = colors.white
- end
- draw_line(2,24,8,col)
- draw_switch(1,24,"|",col)
- draw_switch(10,19,"/",col)
- draw_column(9,20,5,col)
- if rs.testBundledInput("left", colors.black) then
- col = colors.green
- else
- col = colors.white
- end
- draw_column(7,3,12,col)
- draw_column(42,3,12,col)
- draw_switch(6,15,"/",col)
- draw_switch(43,15,"|",col)
- col = colors.white
- --
- draw_switch(4,17,"/",col)
- draw_switch(11,17,"|",col)
- draw_switch(45,17,"|",col)
- draw_switch(48,17,"/",col)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.white)
- touch()
- end
- -- draw-switch--
- function draw_switch(x,y,data,colX)
- mon.setTextColor(colX)
- mon.setCursorPos(x,y)
- mon.write(data)
- mon.setTextColor(colors.white)
- end
- --draw-column-
- function draw_column(x,y,len,colX)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colX)
- len = len + (y - 1)
- for yi = y,len do
- mon.setCursorPos(x,yi)
- mon.write("|")
- yi = yi + 1
- end
- mon.setTextColor(colors.white)
- end
- --draw-line--
- function draw_line(x,y,len,colX)
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colX)
- mon.setCursorPos(x,y)
- for xi=1,len do
- mon.write("-")
- xi = xi + 1
- end
- mon.setTextColor(colors.white)
- end
- --draw-button--
- function draw_button(x,y,len)
- mon.setBackgroundColor(colors.gray)
- mon.setTextColor(colors.white)
- mon.setCursorPos(x,y)
- for xi=1,len do
- mon.write(" ")
- xi = xi + 1
- end
- mon.setBackgroundColor(colors.black)
- end
- --touch event--
- function touch()
- event,side,x,y = os.pullEvent()
- if event == "monitor_touch" then
- if x == 50 and y == 1 then
- power = false
- end
- if x >= 1 and x <= 4 and y == 17 then
- mon.setCursorPos(1,26)
- mon.write("left 4to5")
- modem.transmit(channel,backchan,"white")
- sleep(5)
- modem.transmit(channel,backchan,"orange")
- sleep(2)
- end
- if x >= 7 and x <= 12 and y == 17 then
- mon.setCursorPos(1,26)
- mon.write("left 5to4")
- modem.transmit(channel,backchan,"gray")
- sleep(5)
- modem.transmit(channel,backchan,"yellow")
- sleep(2)
- end
- if x >= 41 and x <= 46 and y == 17 then
- mon.setCursorPos(1,26)
- mon.write("right 4to5")
- modem.transmit(channel,backchan,"green-1")
- sleep(5)
- modem.transmit(channel,backchan,"brown")
- sleep(2)
- end
- if x >= 48 and x <= 50 and y == 17 then
- mon.setCursorPos(1,26)
- mon.write("right 5to4")
- modem.transmit(channel,backchan,"blue")
- sleep(5)
- modem.transmit(channel,backchan,"cyan")
- sleep(2)
- end
- if x >= 19 and x <= 24 and y == 4 then
- mon.setCursorPos(1,26)
- mon.write("track 10")
- modem.transmit(channel,backchan,"yellow-1")
- sleep(5)
- modem.transmit(channel,backchan,"purple-1")
- sleep(2)
- end
- if x >= 19 and x <= 24 and y == 6 then
- mon.setCursorPos(1,26)
- mon.write("track 9")
- modem.transmit(channel,backchan,"lightblue-1")
- sleep(5)
- modem.transmit(channel,backchan,"cyan-1")
- sleep(2)
- end
- if x >= 19 and x <= 24 and y == 8 then
- mon.setCursorPos(1,26)
- mon.write("track 8")
- modem.transmit(channel,backchan,"magenta-1")
- sleep(5)
- modem.transmit(channel,backchan,"lightgray-1")
- sleep(2)
- end
- if x >= 19 and x <= 24 and y == 10 then
- mon.setCursorPos(1,26)
- mon.write("track 7")
- modem.transmit(channel,backchan,"orange-1")
- sleep(5)
- modem.transmit(channel,backchan,"gray-1")
- sleep(2)
- end
- if x >= 19 and x <= 24 and y == 12 then
- mon.setCursorPos(1,26)
- mon.write("track 6")
- modem.transmit(channel,backchan,"white-1")
- sleep(5)
- modem.transmit(channel,backchan,"pink-1")
- sleep(2)
- end
- if x >= 19 and x <= 24 and y == 19 then
- mon.setCursorPos(1,26)
- mon.write("track 3")
- modem.transmit(channel,backchan,"purple")
- sleep(2)
- end
- if x >= 19 and x <= 24 and y == 21 then
- mon.setCursorPos(1,26)
- mon.write("track 2")
- modem.transmit(channel,backchan,"lightgray")
- sleep(5)
- modem.transmit(channel,backchan,"brown-1")
- sleep(2)
- end
- if x >= 19 and x <= 24 and y == 23 then
- mon.setCursorPos(1,26)
- mon.write("track 1")
- modem.transmit(channel,backchan,"lime")
- sleep(5)
- modem.transmit(channel,backchan,"green")
- sleep(2)
- end
- if x >= 9 and x <= 14 and y == 21 then
- mon.setCursorPos(1,26)
- mon.write("track 13")
- modem.transmit(channel,backchan,"lightblue")
- sleep(2)
- end
- if x >= 9 and x <= 14 and y == 23 then
- mon.setCursorPos(1,26)
- mon.write("track 14")
- modem.transmit(channel,backchan,"pink")
- sleep(2)
- end
- if x >= 2 and x <= 7 and y == 15 then
- mon.setCursorPos(1,26)
- mon.write("left")
- modem.transmit(channel,backchan,"magenta")
- sleep(2)
- end
- if x >= 43 and x <= 47 and y == 15 then
- mon.setCursorPos(1,26)
- mon.write("right")
- modem.transmit(channel,backchan,"red")
- sleep(2)
- end
- end
- if power == true then
- draw_screen()
- else
- modem.transmit(channel,backchan,"shutdown")
- shell.run("clear")
- end
- end
- --programm--
- set_monitor()
- draw_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement