SHOW:
|
|
- or go back to the newest paste.
| 1 | print("Capacitor Reader - Host")
| |
| 2 | - | local channel = 70 |
| 2 | + | local channel = 69 |
| 3 | local secretWord = "himama" | |
| 4 | local secretWord2 = "hidada" | |
| 5 | ||
| 6 | local rsSide = "right" | |
| 7 | local updateDelay = 3 | |
| 8 | ||
| 9 | local modem = peripheral.wrap("left")
| |
| 10 | if (not modem) then | |
| 11 | print("Please connect a modem to the left")
| |
| 12 | else | |
| 13 | print("Waiting to connect with client...")
| |
| 14 | modem.open(channel) | |
| 15 | ||
| 16 | while true do | |
| 17 | local sub0, sub1, sub2, sub3, message, sub4 = os.pullEvent("modem_message")
| |
| 18 | print("Received message: " .. message)
| |
| 19 | ||
| 20 | if (message == secretWord) then | |
| 21 | modem.transmit(channel, 1, secretWord2) | |
| 22 | ||
| 23 | print("Connected. Sending Capacitor Updates")
| |
| 24 | sleep(2) | |
| 25 | ||
| 26 | while true do | |
| 27 | term.clear() | |
| 28 | term.setCursorPos(1,1) | |
| 29 | ||
| 30 | local capacitorStatus = rs.getAnalogInput(rsSide) | |
| 31 | modem.transmit(channel, 1, capacitorStatus) | |
| 32 | ||
| 33 | print("Current Status: " .. capacitorStatus)
| |
| 34 | sleep(updateDelay) | |
| 35 | end | |
| 36 | ||
| 37 | break | |
| 38 | else | |
| 39 | print("Received wrong password. Exiting...")
| |
| 40 | break | |
| 41 | end | |
| 42 | end | |
| 43 | ||
| 44 | modem.close(channel) | |
| 45 | end |