Advertisement
kreezxil

ComputerCraft 1.7.10 (v1.6.4) clock with redstone output

Oct 21st, 2014
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --This program can be used to create a digital clock on a monitor peripheral
  2. --The monitor must be placed to the right of the computer
  3.  
  4. print("Running clock application. Hold ctrl + T to end.")
  5. --peripheral.call("right", "setTextScale", 2)
  6.  
  7. local monitor = peripheral.wrap("right")
  8. local sirenSide = "top"
  9. local snooze = false
  10.  
  11. function wipeLine(y)
  12.   monitor.setCursorPos(1,y)
  13.   monitor.write("                      ")
  14. end
  15.  
  16. function setSignal()
  17.   monitor.write("   *ALARM*")
  18.   if redstone.getOutput(sirenSide) then
  19.     -- already set
  20.     return
  21.   else
  22.     redstone.setOutput(sirenSide,true)
  23.   end  
  24. end
  25.  
  26. function unsetSignal()
  27.   if not redstone.getOutput(sirenSide) then
  28.     -- already unset
  29.     return
  30.   else
  31.     redstone.setOutput(sirenSide,false)
  32.   end
  33. end
  34.  
  35. while true do
  36.     local decimalTime = os.time()
  37.     local hours = math.floor(decimalTime)
  38.     local minutes = math.floor((decimalTime - hours) * 100 * 0.6)
  39.  
  40.     local ampm
  41.     if hours > 12 then
  42.         hours = hours - 12
  43.         ampm = "PM"
  44.     else
  45.         ampm = "AM"
  46.     end
  47.     monitor.clear()
  48.     monitor.setCursorPos(1,1)
  49.     if minutes < 10 then
  50.         monitor.write(hours..":0"..minutes.." "..ampm)
  51.     else
  52.         monitor.write(hours..":"..minutes.." "..ampm)
  53.     end
  54.     sleep(.75)
  55.  
  56.     if decimalTime >= 18.541 or decimalTime <= 6.000 then
  57.         setSignal()
  58.     else
  59.         unsetSignal()
  60.     end
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement