Advertisement
surferpup

Monitor Tutorial P2ex1

Feb 8th, 2014
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.69 KB | None | 0 0
  1. local attachedMonitor = peripheral.wrap("top")
  2. local defaultBackgroundColor =colors.black
  3. local defaultTextColor=colors.white
  4.  
  5. local backgroundColorNormal = colors.blue                        
  6. local backgroundColorPressed = colors.red
  7.  
  8. local textColorNormal = colors.white
  9. local textColorPressed = colors.yellow
  10.  
  11. local width=10
  12. local label="button"
  13.  
  14. local startColumn=3
  15. local startRow=3
  16.  
  17. -- Set up Monitor
  18. attachedMonitor.setBackgroundColor(defaultBackgroundColor)
  19. attachedMonitor.setTextColor(defaultTextColor)
  20. attachedMonitor.setTextScale(.5)
  21. attachedMonitor.clear()
  22.  
  23. -- Display the button Background
  24. attachedMonitor.setBackgroundColor(backgroundColorNormal)
  25. attachedMonitor.setCursorPos(startRow,startColumn)
  26. attachedMonitor.write(string.rep(" ",width))
  27.  
  28. --Display the label (auto centered)
  29. attachedMonitor.setTextColor (textColorNormal)
  30. attachedMonitor.setCursorPos(startColumn + math.floor((width - #label)/2),startRow)
  31. attachedMonitor.write(label)
  32.  
  33. -- reset to original text/background colors
  34. attachedMonitor.setBackgroundColor(defaultBackgroundColor)
  35. attachedMonitor.setTextColor(defaultTextColor)
  36.  
  37. -- sleep and then let's do it again with our "pressed" colors.
  38. sleep(3)
  39.  
  40. attachedMonitor.setBackgroundColor(backgroundColorPressed)
  41. attachedMonitor.setCursorPos(startRow,startColumn)
  42. attachedMonitor.write(string.rep(" ",width))
  43. attachedMonitor.setTextColor(textColorPressed)
  44. attachedMonitor.setCursorPos(startColumn + math.floor((width - #label)/2),startRow)
  45. attachedMonitor.write(label)
  46.  
  47. attachedMonitor.setBackgroundColor(defaultBackgroundColor)
  48. attachedMonitor.setTextColor(defaultTextColor)
  49. attachedMonitor.setCursorPos(1,5)    
  50. attachedMonitor.write("Done.")
  51. print()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement