Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- screen size 4*5
- -- set boundled cable with touchscreen
- --local var--
- local power = true
- --cable side
- local CableSide = "right"
- --monitor
- local mon = ""
- --cable state
- local white_st = 0
- local orange_st = 0
- local magenta_st = 0
- local lightblue_st = 0
- local yellow_st = 0
- local lime_st = 0
- local pink_st = 0
- local grey_st = 0
- local lightgrey_st = 0
- local cyan_st = 0
- local purple_st = 0
- local blue_st = 0
- local brown_st = 0
- local green_st = 0
- local red_st = 0
- local black_st = 0
- --display name cable
- local white_na = "Pulverizer"
- local orange_na = "Furnace"
- local magenta_na = "Infuser"
- local lightblue_na = "lightblue"
- local yellow_na = "yellow"
- local lime_na = "lime"
- local pink_na = "pink"
- local grey_na = "grey"
- local lightgrey_na = "lightgrey"
- local cyan_na = "cyan"
- local purple_na = "purple"
- local blue_na = "blue"
- local brown_na = "brown"
- local green_na = "green"
- local red_na = "red"
- local black_na = "black"
- --functions--
- --load API
- shell.run("delete caAPI")
- shell.run("pastebin get EDLdR1nF caAPI")
- os.loadAPI("caAPI")
- --set monitor
- function set_monitor()
- local monitor_number = caAPI.get_hardware("monitor")
- local found = fs.exists("monitor.cfg")
- if found == true then
- file = fs.open("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.white)
- mon.setTextColor(colors.white)
- mon.clear()
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,1)
- mon.setBackgroundColor(colors.blue)
- mon.write("Cabel Control 1.0 CableSide:"..CableSide.." ")
- mon.setCursorPos(50,1)
- mon.setBackgroundColor(colors.red)
- mon.setTextColor(colors.black)
- mon.write("X")
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,2)
- mon.write(white_na)
- mon.setCursorPos(2,3)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if white_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,4)
- mon.write(orange_na)
- mon.setCursorPos(2,5)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if orange_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,6)
- mon.write(magenta_na)
- mon.setCursorPos(2,7)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if magenta_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,8)
- mon.write(lightblue_na)
- mon.setCursorPos(2,9)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if lightblue_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,10)
- mon.write(yellow_na)
- mon.setCursorPos(2,11)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if yellow_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,12)
- mon.write(lime_na)
- mon.setCursorPos(2,13)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if lime_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,14)
- mon.write(pink_na)
- mon.setCursorPos(2,15)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if pink_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,16)
- mon.write(grey_na)
- mon.setCursorPos(2,17)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if grey_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,18)
- mon.write(lightgrey_na)
- mon.setCursorPos(2,19)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if lightgrey_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,20)
- mon.write(cyan_na)
- mon.setCursorPos(2,21)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if cyan_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(1,22)
- mon.write(purple_na)
- mon.setCursorPos(2,23)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if purple_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(24,2)
- mon.write(blue_na)
- mon.setCursorPos(25,3)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if blue_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(24,4)
- mon.write(brown_na)
- mon.setCursorPos(25,5)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if brown_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(24,6)
- mon.write(green_na)
- mon.setCursorPos(25,7)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if green_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(24,8)
- mon.write(red_na)
- mon.setCursorPos(25,9)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if red_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- mon.setCursorPos(24,10)
- mon.write(black_na)
- mon.setCursorPos(25,11)
- mon.setBackgroundColor(colors.gray)
- mon.write(" ")
- mon.setBackgroundColor(colors.white)
- mon.write(" ")
- if black_st == 1 then
- mon.setBackgroundColor(colors.green)
- mon.write("On")
- else
- mon.setBackgroundColor(colors.red)
- mon.write("Off")
- end
- mon.setBackgroundColor(colors.white)
- touch()
- 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 >= 2 and x <= 4 and y == 3 then
- if white_st == 0 then
- white_st = 1
- elseif white_st == 1 then
- white_st = 0
- end
- set_cable("white")
- draw_screen()
- end
- if x >= 2 and x <= 4 and y == 5 then
- if orange_st == 0 then
- orange_st = 1
- elseif orange_st == 1 then
- orange_st = 0
- end
- set_cable("orange")
- draw_screen()
- end
- if x >= 2 and x <= 4 and y == 7 then
- if magenta_st == 0 then
- magenta_st = 1
- elseif magenta_st == 1 then
- magenta_st = 0
- end
- set_cable("magenta")
- draw_screen()
- end
- if x >= 2 and x <= 4 and y == 9 then
- if lightblue_st == 0 then
- lightblue_st = 1
- elseif lightblue_st == 1 then
- lightblue_st = 0
- end
- set_cable("lightblue")
- draw_screen()
- end
- if x >= 2 and x <= 4 and y == 11 then
- if yellow_st == 0 then
- yellow_st = 1
- elseif yellow_st == 1 then
- yellow_st = 0
- end
- set_cable("yellow")
- draw_screen()
- end
- if x >= 2 and x <= 4 and y == 13 then
- if lime_st == 0 then
- lime_st = 1
- elseif lime_st == 1 then
- lime_st = 0
- end
- set_cable("lime")
- draw_screen()
- end
- if x >= 2 and x <= 4 and y == 15 then
- if pink_st == 0 then
- pink_st = 1
- elseif pink_st == 1 then
- pink_st = 0
- end
- set_cable("pink")
- draw_screen()
- end
- if x >= 2 and x <= 4 and y == 17 then
- if grey_st == 0 then
- grey_st = 1
- elseif grey_st == 1 then
- grey_st = 0
- end
- set_cable("grey")
- draw_screen()
- end
- if x >= 2 and x <= 4 and y == 19 then
- if lightgrey_st == 0 then
- lightgrey_st = 1
- elseif lightgrey_st == 1 then
- lightgrey_st = 0
- end
- set_cable("lightgrey")
- draw_screen()
- end
- if x >= 2 and x <= 4 and y == 21 then
- if cyan_st == 0 then
- cyan_st = 1
- elseif cyan_st == 1 then
- cyan_st = 0
- end
- set_cable("cyan")
- draw_screen()
- end
- if x >= 2 and x <= 4 and y == 23 then
- if purple_st == 0 then
- purple_st = 1
- elseif purple_st == 1 then
- purple_st = 0
- end
- set_cable("purple")
- draw_screen()
- end
- if x >= 25 and x <= 29 and y == 3 then
- if blue_st == 0 then
- blue_st = 1
- elseif blue_st == 1 then
- blue_st = 0
- end
- set_cable("blue")
- draw_screen()
- end
- if x >= 25 and x <= 29 and y == 5 then
- if brown_st == 0 then
- brown_st = 1
- elseif brown_st == 1 then
- brown_st = 0
- end
- set_cable("brown")
- draw_screen()
- end
- if x >= 25 and x <= 29 and y == 7 then
- if green_st == 0 then
- green_st = 1
- elseif green_st == 1 then
- green_st = 0
- end
- set_cable("green")
- draw_screen()
- end
- if x >= 25 and x <= 29 and y == 9 then
- if red_st == 0 then
- red_st = 1
- elseif red_st == 1 then
- red_st = 0
- end
- set_cable("red")
- draw_screen()
- end
- if x >= 25 and x <= 29 and y == 11 then
- if black_st == 0 then
- black_st = 1
- elseif black_st == 1 then
- black_st = 0
- end
- set_cable("black")
- draw_screen()
- end
- end
- if power == true then
- draw_screen()
- else
- shell.run("clear")
- end
- end
- --set cable
- function set_cable(cable)
- mon.setCursorPos(24,24)
- mon.write("Set Cable:"..cable)
- color_set = colors.black
- if white_st == 1 then
- color_set = color_set + colors.white
- end
- if orange_st == 1 then
- color_set = color_set + colors.orange
- end
- if magenta_st == 1 then
- color_set = color_set + colors.magenta
- end
- if lightblue_st == 1 then
- color_set = color_set + colors.lightblue
- end
- if yellow_st == 1 then
- color_set = color_set + colors.yellow
- end
- if lime_st == 1 then
- color_set = color_set + colors.lime
- end
- if pink_st == 1 then
- color_set = color_set + colors.pink
- end
- if grey_st == 1 then
- color_set = color_set + colors.gray
- end
- if lightgrey_st == 1 then
- color_set = color_set + colors.lightgray
- end
- if cyan_st == 1 then
- color_set = color_set + colors.cyan
- end
- if purple_st == 1 then
- color_set = color_set + colors.purple
- end
- if blue_st == 1 then
- color_set = color_set + colors.blue
- end
- if brown_st == 1 then
- color_set = color_set + colors.brown
- end
- if green_st == 1 then
- color_set = color_set + colors.green
- end
- if red_st == 1 then
- color_set = color_set + colors.red
- end
- sleep(2)
- rs.setBundledOutput(CableSide,color_set)
- end
- --program
- set_monitor()
- draw_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement