# Coummunications

Infrared (IR) is invisible light with longer wavelengths than visible light, and it is commonly used in TV remote controls to transmit small amounts of data. IR is used in Sphero BOLT to transmit data such as relative distance and heading between robots to enable following and evading behavior among multiple robots, as well as to send custom messages. There are four IR emitters and receivers (pairs) for 360° awareness assuming there is a clear line of sight between two or more robots. The effective range is up to about 3 meters.

startIRBroadcast() sets the IR emitters to broadcast on two specified channels, from 0 to 7, so other BOLTs can follow or evade. The broadcaster uses two channels because the first channel emits near IR pulses (< 1 meter), and the second channel emits far IR pulses (1 to 3 meters) so the following and evading BOLTs can detect these messages on their IR receivers with a sense of relative proximity to the broadcaster. You can't use a channel for more than one purpose at time, such as sending messages along with broadcasting, folllowing, or evading. For example, use startIRBroadcast(0, 1) to broadcast on channels 0 and 1, so that other BOLTs following or evading on 0 and 1 will recognize this robot.

stopIRBroadcast() stops the broadcasting behavior.

### Follow

startIRFollow() sets the IR receivers to look for broadcasting BOLTs on the same channel pair, from 0 to 7. Upon receiving messages from a broadcasting BOLT, the follower will adjust its heading and speed to follow the broadcaster. When a follower loses sight of a broadcaster, the follower will spin in place to search for the broadcaster. You can't use a channel for more than one purpose at time, such as sending messages along with broadcasting, folllowing, or evading. For example, use startIRFollow(0, 1) to follow another BOLT that is broadcasting on channels 0 and 1.

### Stop Following

stopIRFollow() stops the following behavior.

startIREvade() sets the IR receivers to look for broadcasting BOLTs on the same channel pair, from 0 to 7. Upon receiving messages from a broadcasting BOLT, the evader will adjust its heading to roll away from the broadcaster. When an evader loses sight of a broadcaster, the evader will spin in place to search for the broadcaster. The evader may stop if it is in the far range for a period of time so it does not roll too far away from the broadcaster. You can't use a channel for more than one purpose at time, such as sending messages along with broadcasting, folllowing, or evading. For example, use startIREvade(0, 1) to evade another BOLT that is broadcasting on channels 0 and 1.
stopIREvade() stops the evading behavior.
sendIRMessage() sends a message on a given IR channel, at a set intensity, from 1 to 64. Intensity is proportional to proximity, where a 1 is the closest, and 64 is the farthest. For example, use sendIRMessage(4, 5) to send message 4 at intensity 5. You will need to use onIRMessage4(channel) event for on a corresponding robot to receive the message. Also see the getLastIRMessage() sensor to keep track of the last message your robot received. You can't use a channel for more than one purpose at time, such as sending messages along with broadcasting, folllowing, or evading.