Advertisement
cyber_Ahn

Bundled_Cable_Control_Touchscreen

Apr 7th, 2015
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.52 KB | None | 0 0
  1. -- screen size 4*5
  2. -- set boundled cable with touchscreen
  3. --local var--
  4. local power = true
  5. --cable side
  6. local CableSide = "right"
  7. --monitor
  8. local mon = ""
  9. --cable state
  10. local white_st = 0
  11. local orange_st = 0
  12. local magenta_st = 0
  13. local lightblue_st = 0
  14. local yellow_st = 0
  15. local lime_st = 0
  16. local pink_st = 0
  17. local grey_st = 0
  18. local lightgrey_st = 0
  19. local cyan_st = 0
  20. local purple_st = 0
  21. local blue_st = 0
  22. local brown_st = 0
  23. local green_st = 0
  24. local red_st = 0
  25. local black_st = 0
  26. --display name cable
  27. local white_na = "Pulverizer"
  28. local orange_na = "Furnace"
  29. local magenta_na = "Infuser"
  30. local lightblue_na = "lightblue"
  31. local yellow_na = "yellow"
  32. local lime_na = "lime"
  33. local pink_na = "pink"
  34. local grey_na = "grey"
  35. local lightgrey_na = "lightgrey"
  36. local cyan_na = "cyan"
  37. local purple_na = "purple"
  38. local blue_na = "blue"
  39. local brown_na = "brown"
  40. local green_na = "green"
  41. local red_na = "red"
  42. local black_na = "black"
  43. --functions--
  44. --load API
  45. shell.run("delete caAPI")
  46. shell.run("pastebin get EDLdR1nF caAPI")
  47. os.loadAPI("caAPI")
  48. --set monitor
  49. function set_monitor()
  50. local monitor_number = caAPI.get_hardware("monitor")
  51. local found = fs.exists("monitor.cfg")
  52. if found == true then
  53. file = fs.open("monitor.cfg","r")
  54. local fileData = {}
  55. local line = file.readLine()
  56. repeat
  57. table.insert(fileData,line)
  58. line = file.readLine()
  59. until line == nil
  60. file.close()
  61. monitor_number = fileData[1]
  62. end
  63. mon = peripheral.wrap(monitor_number)
  64. end
  65. --draw screen
  66. function draw_screen()
  67. mon.setBackgroundColor(colors.white)
  68. mon.setTextColor(colors.white)
  69. mon.clear()
  70. mon.setBackgroundColor(colors.white)
  71. mon.setCursorPos(1,1)
  72. mon.setBackgroundColor(colors.blue)
  73. mon.write("Cabel Control 1.0      CableSide:"..CableSide.."                    ")
  74. mon.setCursorPos(50,1)
  75. mon.setBackgroundColor(colors.red)
  76. mon.setTextColor(colors.black)
  77. mon.write("X")
  78. mon.setBackgroundColor(colors.white)
  79. mon.setCursorPos(1,2)
  80. mon.write(white_na)
  81. mon.setCursorPos(2,3)
  82. mon.setBackgroundColor(colors.gray)
  83. mon.write("    ")
  84. mon.setBackgroundColor(colors.white)
  85. mon.write(" ")
  86. if white_st == 1 then
  87. mon.setBackgroundColor(colors.green)
  88. mon.write("On")
  89. else
  90. mon.setBackgroundColor(colors.red)
  91. mon.write("Off")
  92. end
  93. mon.setBackgroundColor(colors.white)
  94. mon.setCursorPos(1,4)
  95. mon.write(orange_na)
  96. mon.setCursorPos(2,5)
  97. mon.setBackgroundColor(colors.gray)
  98. mon.write("    ")
  99. mon.setBackgroundColor(colors.white)
  100. mon.write(" ")
  101. if orange_st == 1 then
  102. mon.setBackgroundColor(colors.green)
  103. mon.write("On")
  104. else
  105. mon.setBackgroundColor(colors.red)
  106. mon.write("Off")
  107. end
  108. mon.setBackgroundColor(colors.white)
  109. mon.setCursorPos(1,6)
  110. mon.write(magenta_na)
  111. mon.setCursorPos(2,7)
  112. mon.setBackgroundColor(colors.gray)
  113. mon.write("    ")
  114. mon.setBackgroundColor(colors.white)
  115. mon.write(" ")
  116. if magenta_st == 1 then
  117. mon.setBackgroundColor(colors.green)
  118. mon.write("On")
  119. else
  120. mon.setBackgroundColor(colors.red)
  121. mon.write("Off")
  122. end
  123. mon.setBackgroundColor(colors.white)
  124. mon.setCursorPos(1,8)
  125. mon.write(lightblue_na)
  126. mon.setCursorPos(2,9)
  127. mon.setBackgroundColor(colors.gray)
  128. mon.write("    ")
  129. mon.setBackgroundColor(colors.white)
  130. mon.write(" ")
  131. if lightblue_st == 1 then
  132. mon.setBackgroundColor(colors.green)
  133. mon.write("On")
  134. else
  135. mon.setBackgroundColor(colors.red)
  136. mon.write("Off")
  137. end
  138. mon.setBackgroundColor(colors.white)
  139. mon.setCursorPos(1,10)
  140. mon.write(yellow_na)
  141. mon.setCursorPos(2,11)
  142. mon.setBackgroundColor(colors.gray)
  143. mon.write("    ")
  144. mon.setBackgroundColor(colors.white)
  145. mon.write(" ")
  146. if yellow_st == 1 then
  147. mon.setBackgroundColor(colors.green)
  148. mon.write("On")
  149. else
  150. mon.setBackgroundColor(colors.red)
  151. mon.write("Off")
  152. end
  153. mon.setBackgroundColor(colors.white)
  154. mon.setCursorPos(1,12)
  155. mon.write(lime_na)
  156. mon.setCursorPos(2,13)
  157. mon.setBackgroundColor(colors.gray)
  158. mon.write("    ")
  159. mon.setBackgroundColor(colors.white)
  160. mon.write(" ")
  161. if lime_st == 1 then
  162. mon.setBackgroundColor(colors.green)
  163. mon.write("On")
  164. else
  165. mon.setBackgroundColor(colors.red)
  166. mon.write("Off")
  167. end
  168. mon.setBackgroundColor(colors.white)
  169. mon.setCursorPos(1,14)
  170. mon.write(pink_na)
  171. mon.setCursorPos(2,15)
  172. mon.setBackgroundColor(colors.gray)
  173. mon.write("    ")
  174. mon.setBackgroundColor(colors.white)
  175. mon.write(" ")
  176. if pink_st == 1 then
  177. mon.setBackgroundColor(colors.green)
  178. mon.write("On")
  179. else
  180. mon.setBackgroundColor(colors.red)
  181. mon.write("Off")
  182. end
  183. mon.setBackgroundColor(colors.white)
  184. mon.setCursorPos(1,16)
  185. mon.write(grey_na)
  186. mon.setCursorPos(2,17)
  187. mon.setBackgroundColor(colors.gray)
  188. mon.write("    ")
  189. mon.setBackgroundColor(colors.white)
  190. mon.write(" ")
  191. if grey_st == 1 then
  192. mon.setBackgroundColor(colors.green)
  193. mon.write("On")
  194. else
  195. mon.setBackgroundColor(colors.red)
  196. mon.write("Off")
  197. end
  198. mon.setBackgroundColor(colors.white)
  199. mon.setCursorPos(1,18)
  200. mon.write(lightgrey_na)
  201. mon.setCursorPos(2,19)
  202. mon.setBackgroundColor(colors.gray)
  203. mon.write("    ")
  204. mon.setBackgroundColor(colors.white)
  205. mon.write(" ")
  206. if lightgrey_st == 1 then
  207. mon.setBackgroundColor(colors.green)
  208. mon.write("On")
  209. else
  210. mon.setBackgroundColor(colors.red)
  211. mon.write("Off")
  212. end
  213. mon.setBackgroundColor(colors.white)
  214. mon.setCursorPos(1,20)
  215. mon.write(cyan_na)
  216. mon.setCursorPos(2,21)
  217. mon.setBackgroundColor(colors.gray)
  218. mon.write("    ")
  219. mon.setBackgroundColor(colors.white)
  220. mon.write(" ")
  221. if cyan_st == 1 then
  222. mon.setBackgroundColor(colors.green)
  223. mon.write("On")
  224. else
  225. mon.setBackgroundColor(colors.red)
  226. mon.write("Off")
  227. end
  228. mon.setBackgroundColor(colors.white)
  229. mon.setCursorPos(1,22)
  230. mon.write(purple_na)
  231. mon.setCursorPos(2,23)
  232. mon.setBackgroundColor(colors.gray)
  233. mon.write("    ")
  234. mon.setBackgroundColor(colors.white)
  235. mon.write(" ")
  236. if purple_st == 1 then
  237. mon.setBackgroundColor(colors.green)
  238. mon.write("On")
  239. else
  240. mon.setBackgroundColor(colors.red)
  241. mon.write("Off")
  242. end
  243. mon.setBackgroundColor(colors.white)
  244. mon.setCursorPos(24,2)
  245. mon.write(blue_na)
  246. mon.setCursorPos(25,3)
  247. mon.setBackgroundColor(colors.gray)
  248. mon.write("    ")
  249. mon.setBackgroundColor(colors.white)
  250. mon.write(" ")
  251. if blue_st == 1 then
  252. mon.setBackgroundColor(colors.green)
  253. mon.write("On")
  254. else
  255. mon.setBackgroundColor(colors.red)
  256. mon.write("Off")
  257. end
  258. mon.setBackgroundColor(colors.white)
  259. mon.setCursorPos(24,4)
  260. mon.write(brown_na)
  261. mon.setCursorPos(25,5)
  262. mon.setBackgroundColor(colors.gray)
  263. mon.write("    ")
  264. mon.setBackgroundColor(colors.white)
  265. mon.write(" ")
  266. if brown_st == 1 then
  267. mon.setBackgroundColor(colors.green)
  268. mon.write("On")
  269. else
  270. mon.setBackgroundColor(colors.red)
  271. mon.write("Off")
  272. end
  273. mon.setBackgroundColor(colors.white)
  274. mon.setCursorPos(24,6)
  275. mon.write(green_na)
  276. mon.setCursorPos(25,7)
  277. mon.setBackgroundColor(colors.gray)
  278. mon.write("    ")
  279. mon.setBackgroundColor(colors.white)
  280. mon.write(" ")
  281. if green_st == 1 then
  282. mon.setBackgroundColor(colors.green)
  283. mon.write("On")
  284. else
  285. mon.setBackgroundColor(colors.red)
  286. mon.write("Off")
  287. end
  288. mon.setBackgroundColor(colors.white)
  289. mon.setCursorPos(24,8)
  290. mon.write(red_na)
  291. mon.setCursorPos(25,9)
  292. mon.setBackgroundColor(colors.gray)
  293. mon.write("    ")
  294. mon.setBackgroundColor(colors.white)
  295. mon.write(" ")
  296. if red_st == 1 then
  297. mon.setBackgroundColor(colors.green)
  298. mon.write("On")
  299. else
  300. mon.setBackgroundColor(colors.red)
  301. mon.write("Off")
  302. end
  303. mon.setBackgroundColor(colors.white)
  304. mon.setCursorPos(24,10)
  305. mon.write(black_na)
  306. mon.setCursorPos(25,11)
  307. mon.setBackgroundColor(colors.gray)
  308. mon.write("    ")
  309. mon.setBackgroundColor(colors.white)
  310. mon.write(" ")
  311. if black_st == 1 then
  312. mon.setBackgroundColor(colors.green)
  313. mon.write("On")
  314. else
  315. mon.setBackgroundColor(colors.red)
  316. mon.write("Off")
  317. end
  318. mon.setBackgroundColor(colors.white)
  319. touch()
  320. end
  321. --touch event--
  322. function touch()
  323. event,side,x,y = os.pullEvent()
  324. if event == "monitor_touch" then
  325. if x == 50 and y == 1 then
  326. power = false
  327. end
  328. if x >= 2 and x <= 4 and y == 3 then
  329. if white_st == 0 then
  330. white_st = 1
  331. elseif white_st == 1 then
  332. white_st = 0
  333. end
  334. set_cable("white")
  335. draw_screen()
  336. end
  337. if x >= 2 and x <= 4 and y == 5 then
  338. if orange_st == 0 then
  339. orange_st = 1
  340. elseif orange_st == 1 then
  341. orange_st = 0
  342. end
  343. set_cable("orange")
  344. draw_screen()
  345. end
  346. if x >= 2 and x <= 4 and y == 7 then
  347. if magenta_st == 0 then
  348. magenta_st = 1
  349. elseif magenta_st == 1 then
  350. magenta_st = 0
  351. end
  352. set_cable("magenta")
  353. draw_screen()
  354. end
  355. if x >= 2 and x <= 4 and y == 9 then
  356. if lightblue_st == 0 then
  357. lightblue_st = 1
  358. elseif lightblue_st == 1 then
  359. lightblue_st = 0
  360. end
  361. set_cable("lightblue")
  362. draw_screen()
  363. end
  364. if x >= 2 and x <= 4 and y == 11 then
  365. if yellow_st == 0 then
  366. yellow_st = 1
  367. elseif yellow_st == 1 then
  368. yellow_st = 0
  369. end
  370. set_cable("yellow")
  371. draw_screen()
  372. end
  373. if x >= 2 and x <= 4 and y == 13 then
  374. if lime_st == 0 then
  375. lime_st = 1
  376. elseif lime_st == 1 then
  377. lime_st = 0
  378. end
  379. set_cable("lime")
  380. draw_screen()
  381. end
  382. if x >= 2 and x <= 4 and y == 15 then
  383. if pink_st == 0 then
  384. pink_st = 1
  385. elseif pink_st == 1 then
  386. pink_st = 0
  387. end
  388. set_cable("pink")
  389. draw_screen()
  390. end
  391. if x >= 2 and x <= 4 and y == 17 then
  392. if grey_st == 0 then
  393. grey_st = 1
  394. elseif grey_st == 1 then
  395. grey_st = 0
  396. end
  397. set_cable("grey")
  398. draw_screen()
  399. end
  400. if x >= 2 and x <= 4 and y == 19 then
  401. if lightgrey_st == 0 then
  402. lightgrey_st = 1
  403. elseif lightgrey_st == 1 then
  404. lightgrey_st = 0
  405. end
  406. set_cable("lightgrey")
  407. draw_screen()
  408. end
  409. if x >= 2 and x <= 4 and y == 21 then
  410. if cyan_st == 0 then
  411. cyan_st = 1
  412. elseif cyan_st == 1 then
  413. cyan_st = 0
  414. end
  415. set_cable("cyan")
  416. draw_screen()
  417. end
  418. if x >= 2 and x <= 4 and y == 23 then
  419. if purple_st == 0 then
  420. purple_st = 1
  421. elseif purple_st == 1 then
  422. purple_st = 0
  423. end
  424. set_cable("purple")
  425. draw_screen()
  426. end
  427. if x >= 25 and x <= 29 and y == 3 then
  428. if blue_st == 0 then
  429. blue_st = 1
  430. elseif blue_st == 1 then
  431. blue_st = 0
  432. end
  433. set_cable("blue")
  434. draw_screen()
  435. end
  436. if x >= 25 and x <= 29 and y == 5 then
  437. if brown_st == 0 then
  438. brown_st = 1
  439. elseif brown_st == 1 then
  440. brown_st = 0
  441. end
  442. set_cable("brown")
  443. draw_screen()
  444. end
  445. if x >= 25 and x <= 29 and y == 7 then
  446. if green_st == 0 then
  447. green_st = 1
  448. elseif green_st == 1 then
  449. green_st = 0
  450. end
  451. set_cable("green")
  452. draw_screen()
  453. end
  454. if x >= 25 and x <= 29 and y == 9 then
  455. if red_st == 0 then
  456. red_st = 1
  457. elseif red_st == 1 then
  458. red_st = 0
  459. end
  460. set_cable("red")
  461. draw_screen()
  462. end
  463. if x >= 25 and x <= 29 and y == 11 then
  464. if black_st == 0 then
  465. black_st = 1
  466. elseif black_st == 1 then
  467. black_st = 0
  468. end
  469. set_cable("black")
  470. draw_screen()
  471. end
  472. end
  473. if power == true then
  474. draw_screen()
  475. else
  476. shell.run("clear")
  477. end
  478. end
  479. --set cable
  480. function set_cable(cable)
  481. mon.setCursorPos(24,24)
  482. mon.write("Set Cable:"..cable)
  483. color_set = colors.black
  484. if white_st == 1 then
  485. color_set = color_set + colors.white
  486. end
  487. if orange_st == 1 then
  488. color_set = color_set + colors.orange
  489. end
  490. if magenta_st == 1 then
  491. color_set = color_set + colors.magenta
  492. end
  493. if lightblue_st == 1 then
  494. color_set = color_set + colors.lightblue
  495. end
  496. if yellow_st == 1 then
  497. color_set = color_set + colors.yellow
  498. end
  499. if lime_st == 1 then
  500. color_set = color_set + colors.lime
  501. end
  502. if pink_st == 1 then
  503. color_set = color_set + colors.pink
  504. end
  505. if grey_st == 1 then
  506. color_set = color_set + colors.gray
  507. end
  508. if lightgrey_st == 1 then
  509. color_set = color_set + colors.lightgray
  510. end
  511. if cyan_st == 1 then
  512. color_set = color_set + colors.cyan
  513. end
  514. if purple_st == 1 then
  515. color_set = color_set + colors.purple
  516. end
  517. if blue_st == 1 then
  518. color_set = color_set + colors.blue
  519. end
  520. if brown_st == 1 then
  521. color_set = color_set + colors.brown
  522. end
  523. if green_st == 1 then
  524. color_set = color_set + colors.green
  525. end
  526. if red_st == 1 then
  527. color_set = color_set + colors.red
  528. end
  529. sleep(2)
  530. rs.setBundledOutput(CableSide,color_set)
  531. end
  532. --program
  533. set_monitor()
  534. draw_screen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement