Advertisement
RavenSH4

Wireless reader

May 15th, 2022 (edited)
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. --Global variables
  2. --21 send, 22-receive
  3. mouseWidth = 0
  4. mouseHeight = 0
  5.  
  6. ------------------
  7. StartLine = 1
  8. currentLine = StartLine
  9. MaxLine = 12
  10. ------------------
  11. --initialize
  12. monitor = peripheral.wrap("right")
  13. monitor.clear()
  14. monitor.setCursorPos(1,1)
  15. monitor.write("INITIALIZE")
  16. --
  17. modem = peripheral.wrap("bottom")
  18. modem.open(21)
  19.  
  20. --Write On/Off button
  21. function WriteButtons(IsOn)
  22.     monitor.setTextColor(colors.white)
  23.     if IsOn == true then
  24.         monitor.setBackgroundColour((colours.lime))
  25.         monitor.setCursorPos(24,2)
  26.         monitor.write("     ")
  27.         monitor.setCursorPos(24,3)
  28.         monitor.write(" ON  ")
  29.         monitor.setCursorPos(24,4)
  30.         monitor.write("     ")
  31.     else
  32.         monitor.setBackgroundColour((colours.red))
  33.         monitor.setCursorPos(24,2)
  34.         monitor.write("     ")
  35.         monitor.setCursorPos(24,3)
  36.         monitor.write(" OFF ")
  37.         monitor.setCursorPos(24,4)
  38.         monitor.write("     ")
  39.     end
  40.     monitor.setBackgroundColour((colours.black))  
  41. end
  42.  
  43. --Check mouse to button click
  44. function checkClickPosition()
  45.   if mouseWidth >= 24 and mouseWidth <= 28 and mouseHeight >= 2 and mouseHeight <= 4 then
  46.     --WriteButtons(IsOnFlag)
  47.     --UpdateSensors()
  48.   end
  49. end
  50.  
  51. --
  52. function DrawMessage(Text)
  53.     if (currentLine > MaxLine) then
  54.         currentLine = StartLine
  55.         monitor.clear()
  56.     end
  57.  
  58.     DrawTextLine(colors.white, currentLine, Text)
  59.     currentLine = currentLine + 1
  60. end
  61.  
  62. --
  63. function DrawTextLine(Color, Line, TextH)
  64.   monitor.setCursorPos(1,Line)
  65.   monitor.setTextColor(Color)
  66.   monitor.write(TextH)
  67. end
  68.  
  69. ------------------
  70. w,h=monitor.getSize()
  71. print(w)
  72. print(h)
  73.  
  74. repeat
  75.     --local myTimer = os.startTimer(1)
  76.  
  77.     event,p1,p2,p3,p4,p5 = os.pullEvent()
  78.     if event=="monitor_touch" then
  79.         mouseWidth = p2 -- sets mouseWidth
  80.         mouseHeight = p3 -- and mouseHeight
  81.         checkClickPosition() -- this runs our function
  82.     end
  83.     --
  84.     if (event=="modem_message") then
  85.         --event, side, channel, replyChannel, message, distance
  86.         DrawMessage(p4)
  87.     end
  88.     --
  89.     --if event=="timer" then
  90.     --
  91.     --end
  92. until event=="char" and p1==("q")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement