Posted 27 June 2012 - 11:29 PM
While trying to learn how to get the turtles to function I learned a few things let me share them. First you need a computer with a modem and a wireless turtle.Then you need to know the turtles ids you can get it by typing id at the turtles prompt. The turtle will respond This is computer 1 or 2 or 5 please note this. Now we need to get the turtle to listen for instructions
Turtles code save it to a file and name it listen
Computers code save it to a file named makedance
Thats all we need
now stand back and watch the turtle dance. Click on the turtle to stop it dancing.
This method is easy to modify to make the turtle do what ever you want. I can expand on this topic if anyone needs me to.
Turtles code save it to a file and name it listen
rednet.open("right")
print("Waiting for command")
id, message = rednet.receive()
term.clear()
if message == "test" then
shell.run("dance")
else
print("Does Not Compute")
end
- rednet.open("right")–starts the turtle listening for a message.
- print("Waiting for command")– prints on the screen Waiting for command until an event happens
- id, message = rednet.receive()– Sets up the receive event the computer will send its id# and a message. The message will always be a string.
- term.clear()– clears the screen
- if message == "test" then – once a message is received and it equals the if test then it executes the next line
- shell.run("dance")– Shell.run will execute what ever program that is stated. dance is an included CC program else the the received message does not equal the if test then the next line is executed print("Does Not Compute")– prints on the screen Does Not Compute end– ends the if statement
Computers code save it to a file named makedance
rednet.open("right")
rednet.send(2, "test")
Thats all we need
- rednet.open("right")– right equals the side of the computer the modem is on it could be left top bottom etc
- rednet.send(2, "test")– the 2 equals the turtles id and test is the message. Remember test from our if statement above if we send the turtle test it will make it dance if we send it anything else it will print out Does not compute.
now stand back and watch the turtle dance. Click on the turtle to stop it dancing.
This method is easy to modify to make the turtle do what ever you want. I can expand on this topic if anyone needs me to.