SHOW:
|
|
- or go back to the newest paste.
| 1 | local modem = peripheral.wrap("left")
| |
| 2 | rednet.open("left")
| |
| 3 | local speaker = peripheral.find("speaker")
| |
| 4 | local dfpwm = require("cc.audio.dfpwm")
| |
| 5 | function playMusic(name) | |
| 6 | local decoder = dfpwm.make_decoder() | |
| 7 | for chunk in io.lines(name 16 * 1024) do | |
| 8 | local buffer = decoder(chunk) | |
| 9 | ||
| 10 | while not speaker.playAudio(buffer) do | |
| 11 | os.pullEvent("speaker_audio_empty")
| |
| 12 | end | |
| 13 | end | |
| 14 | end | |
| 15 | print("Waiting for papa...")
| |
| 16 | local papa = "" | |
| 17 | local id = "" | |
| 18 | repeat | |
| 19 | local senderId, message, protocol = rednet.receive() | |
| 20 | papa = senderId | |
| 21 | id = senderId | |
| 22 | until (message == "pair") and (protocol == "tmzst") | |
| 23 | print("get request from "..id)
| |
| 24 | rednet.send(papa,os.getComputerID(),"tmzst") | |
| 25 | papa = senderId | |
| 26 | local function receive() | |
| 27 | while true do | |
| 28 | local senderId, ms, protocol = rednet.receive() | |
| 29 | print(ms) | |
| 30 | if (senderId == id) and (protocol == "tmzst") then | |
| 31 | if ms == "w" then | |
| 32 | print("fw")
| |
| 33 | turtle.forward() | |
| 34 | elseif ms == "s" then | |
| 35 | turtle.back() | |
| 36 | elseif ms == "a" then | |
| 37 | turtle.turnLeft() | |
| 38 | elseif ms == "d" then | |
| 39 | turtle.turnRight() | |
| 40 | elseif ms == "shift" then | |
| 41 | turtle.up() | |
| 42 | elseif ms == "ctrl" then | |
| 43 | turtle.down() | |
| 44 | elseif ms == "e" then | |
| 45 | turtle.dig() | |
| 46 | elseif ms == "q" then | |
| 47 | turtle.select(2) | |
| 48 | turtle.place() | |
| 49 | turtle.select(1) | |
| 50 | elseif ms == "r" then | |
| 51 | repeat | |
| 52 | turtle.forward() | |
| 53 | local senderId, msg, protocol = rednet.receive("tmzst",1)
| |
| 54 | until msg == "r" | |
| 55 | end | |
| 56 | end | |
| 57 | end | |
| 58 | end | |
| 59 | local function send() | |
| 60 | while true do | |
| 61 | sleep(1) | |
| 62 | rednet.send(id,turtle.getFuelLevel(),"tmzstf") | |
| 63 | turtle.refuel() | |
| 64 | end | |
| 65 | end | |
| 66 | parallel.waitForAll(send,receive) |