SHOW:
|
|
- or go back to the newest paste.
| 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)
|
| 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 | - | |
| 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 | - | if hours >= 18 and hours <= 6 then |
| 29 | + | return |
| 30 | - | if minutes >= 32 and hours == 18 then |
| 30 | + | else |
| 31 | - | redstone.setOutput("top", true)
|
| 31 | + | redstone.setOutput(sirenSide,false) |
| 32 | end | |
| 33 | - | redstone.setOutput("top", true)
|
| 33 | + | end |
| 34 | ||
| 35 | - | else |
| 35 | + | |
| 36 | - | redstone.setOutput("top", false)
|
| 36 | + | |
| 37 | - | end |
| 37 | + | |
| 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 |