Advertisement
Guest User

startup

a guest
May 13th, 2021
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.87 KB | None | 0 0
  1.  
  2.  ----------    Setup & Configuration    ----------
  3.  
  4.  
  5.  
  6.  
  7. -- Boot Sequence --
  8.  
  9.     sp1 = peripheral.wrap("speaker_11")
  10.     sp2 = peripheral.wrap("speaker_12")
  11.     sp3 = peripheral.wrap("speaker_13")
  12.      --Declare what speakers to use
  13.    
  14.     monitor = peripheral.wrap("top")
  15.      --Declare where the monitor is
  16.      
  17.     monitor.clear()
  18.      --Clear the monitor
  19.      
  20.     monitor.setCursorPos(1, 1)
  21.      --Set the cursor position to the top left
  22.  
  23.  
  24.  
  25.  
  26. -- Variable Creation --
  27.  
  28.     w,h = monitor.getSize()
  29.      --Grab the monitor dimensions
  30.  
  31.     mouseWidth = 0
  32.     mouseHeight = 0
  33.      --Mouse position on screen
  34.  
  35.     monitorPosX, monitorPosY = monitor.getCursorPos()
  36.      --Grab the current monitor text position
  37.    
  38.     on = false
  39.      --Is the alarm currently on?
  40.    
  41.     quit = false
  42.      --A variable used to exit the program
  43.    
  44.     quitTimeout = false
  45.      --Also used to end the program
  46.  
  47.  
  48.  
  49. -- Status Message --
  50.    
  51.     term.setCursorPos(1, 1)
  52.     term.clear()
  53.    
  54.     print("")
  55.     print("Program Running: Beats by Dewrot")
  56.     print("")
  57.     print("Monitor Width:", w)
  58.     print("Monitor Height:", h)
  59.     print("")
  60.     print("Monitor Position:", "("..monitorPosX..","..monitorPosY..")")
  61.     print("")
  62.     print("Status: Off")
  63.     print("")
  64.     print("")
  65.     print("")
  66.    
  67.     term.setTextColor((colors.yellow))
  68.     print("Press 'X' to end program anytime.")
  69.     term.setTextColor((colors.white))
  70.    
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. --------------    Draw the Screen    --------------
  79.  
  80.  
  81.  
  82.  
  83.  
  84. -- Button Creation --
  85.    
  86.     function drawScreen()
  87.    
  88.       monitor.setBackgroundColor((colors.black))
  89.        --Makes sure the background is black
  90.       monitor.setCursorPos(1,1)
  91.       monitor.write("Beats")
  92.        --Name of the program  
  93.    
  94.       monitor.setBackgroundColor((colors.red))
  95.        --Sets background of text to red
  96.       monitor.setCursorPos(7,1)
  97.       monitor.write("*")
  98.        --The "EXIT" button
  99.    
  100.       if on ~= true then
  101.         monitor.setBackgroundColor((colors.gray))
  102.         monitor.setCursorPos(2,3)
  103.         monitor.write(" ON  ")
  104.          --The "ON" button
  105.      
  106.         monitor.setBackgroundColor((colors.lime))
  107.         monitor.setCursorPos(2,5)
  108.         monitor.write(" OFF ")
  109.          --The "OFF" button
  110.          
  111.         monitor.setBackgroundColor((colors.black))
  112.        
  113.      
  114.       elseif on == true then
  115.         monitor.setBackgroundColor((colors.lime))
  116.         monitor.setCursorPos(2,3)
  117.         monitor.write(" ON  ")
  118.    
  119.         monitor.setBackgroundColor((colors.gray))
  120.         monitor.setCursorPos(2,5)
  121.         monitor.write(" OFF ")
  122.      
  123.         monitor.setBackgroundColor((colors.black))
  124.        
  125.       elseif quitTimeout == true then
  126.         monitor.setCursorPos(1,1)
  127.         monitor.setBackgroundColor((colors.black))
  128.         monitor.clear()
  129.        
  130.       end
  131.      
  132.     end
  133.  
  134. -- Placing Screen Elements --
  135.      
  136.     drawScreen()
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143. ---------------    Button  Logic    ---------------
  144.  
  145.  
  146.  
  147.  
  148. -- Button Functions --
  149.  
  150.     function checkClickPosition()
  151.       if mouseWidth == 7 and mouseHeight == 1 then
  152.        --Red X button was pressed
  153.       quit = true
  154.        --Set the quit variable to true
  155.       os.startTimer(0.1)
  156.      
  157.       elseif mouseWidth > 1 and mouseWidth < 7 and mouseHeight == 3 then
  158.        --On button was pressed
  159.      
  160.         if on == true then
  161.           return
  162.        
  163.         elseif on ~= true then
  164.           on = true
  165.           term.setCursorPos(9,9)
  166.           term.write("On ")
  167.           os.startTimer(0.1)
  168.         end
  169.      
  170.      
  171.       elseif mouseWidth > 1 and mouseWidth < 7 and mouseHeight == 5 then
  172.        --Off button was pressed
  173.      
  174.         if on == true then
  175.           on = false
  176.           term.setCursorPos(9,9)
  177.           term.write("Off")
  178.      
  179.         elseif on ~= true then
  180.           return
  181.         end
  182.          
  183.          
  184.       end
  185.      
  186.     end
  187.    
  188.    
  189.    
  190.     repeat
  191.       event,p1,p2,p3 = os.pullEvent()
  192.        
  193.         if event=="monitor_touch" then
  194.           mouseWidth = p2
  195.           mouseHeight = p3
  196.           checkClickPosition()
  197.           drawScreen()
  198.          
  199.         elseif event=="char" and p1 =="x" then
  200.           term.clear()
  201.           term.setCursorPos(1,1)
  202.           monitor.clear()
  203.           monitor.setCursorPos(1,1)
  204.           quitTimeout = true
  205.            
  206.        
  207.         elseif on and event=="timer" and quit== false then
  208.         sp1.playSound("biomemakeover:red_rose", 3.0, 1)
  209.         sp2.playSound("biomemakeover:red_rose", 3.0, 1)
  210.         sp3.playSound("bimoemakeover:red_rose", 1.5, 1)
  211.         os.startTimer(125.10)
  212.        
  213.         elseif quit==true then
  214.           term.clear()
  215.           term.setCursorPos(1,1)
  216.           monitor.clear()
  217.           monitor.setCursorPos(1,1)
  218.  
  219.           quitTimeout = true
  220.        
  221.         end
  222.      
  223.     until quitTimeout==true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement