
APPENDIX C 393
Chapter 6
IR transmit example
Language: Wiring/Arduino
This program reads an analog input on pin 0 and sends
the result out as an ASCII-encoded string. The TX line of
the microcontroller is connected to a Rentron TX-IRHS IR
transmitter which can transmit at 19200 bps.
void setup(){
//Open the serial port at 19200 bps:
Serial.begin(19200);
}
void loop(){
// Read the analog input:
int analogValue = analogRead(0);
// send the value out via the transmitter:
Serial.println(analogValue, DEC);
// delay 10ms to allow the analog-to-digital receiver to settle:
delay(10);
}
RF Transmitter
Language: Wiring/Arduino
This program reads an analog input on pin 0 and sends the
result out as an ASCII-encoded string. The TX line of the
microcontroller is connected to an RF transmitter that is
capable of reading at 2400 bps.
void setup(){
// Open the serial port at 2400 bps:
Serial.begin(2400);
}
void loop(){
// Read the analog input:
int analogValue = analogRead(0);
// send the value out via the transmitter:
Serial.println(analogValue, DEC);
// delay 10ms to allow the analog-to-digital receiver to settle:
delay(10);
}
RF Receive
Language: Processing
This program listens for data coming in through a serial
port. It reads a string and throws out any strings that
contain values other than ASCII numerals, linefeed, or
carriage return, or that are longer than four digits. ...