IR Controller
Infrared Controller can be used to emit IR signals to control different A/V devices as well as recieve (learn) IR signals from existing remote controls.Z-Uno IR Controller supports up 4 outputs (pins 4–6, IR_TX2–IR_TX0, see pinout) and one input (pin 7 or IR_RX).
There are two ways to specify a command:
- Raw mode defined by sequency of marks and spaces
- Vendor command mode defined by encoding protocol type and command in the protocol
IRController.h defines supported vendors encodings and settings for raw mode. IR controller is only available in unsecure or S0 security mode. S2 security mode can be supported on demand - write us. To set up IR controller use IR.begin(ir_params). Depending in object passed to IR.begin() IR controller will be configure accordingly. Possible objects are IRReceiverParams or IRTransmitterParams. In raw mode buffer size is 300 bytes (marks/space sequences), this is about 9 bytes of IR-commands data. This is enough for all A/V and most A/C commands. Example of usage in receiver mode:
#include "IRController.h"
IRReceiverParams ir_receiver(IR_FLAGS_IO_INVERTED);
IRCommand_t ir_cmd;
word raw_data[200];
void setup() {
IR.begin(&ir_receiver);
IR.scan();
}
void loop() {
// Check state of IR-controller
byte ir_state = IR.getState();
if (!(ir_state & IR_STATUS_BUSY)) {
...
// Extract data in RAW16 format
// see IRController.h for detailed descriptions
IR.recv_raw16(raw_data);
// In some cases it is possible to detect command by vendor
if (IR.detectCommand(&ir_cmd)) {
// ir_cmd stores the command detected
}
// restart scan process
IR.scan();
}
delay(500);
}
Example of usage in transmitter mode:
#include "IRController.h"
IRTransmitterParams ir_transmitter(byte(IR_TRANSMITTER_OUTPUT_PIN6),
IR_FLAGS_OUTPUT_HIGHDRIVE,
IR_MS_PRESCALLER_4MHZ,
IR_CARRIER_PRESCALLER_8MHZ);
// Raw
word raw_command[] = { ... };
// or by Vendor
IRCommand_t vendor_cmd;
void setup() {
// For Raw
ir_transmitter.setupVendor(SOME_VENDOR);
IR.begin(&ir_transmitter);
// or by Vendor
vendor_cmd.vendor = MY_IR_VENDOR;
vendor_cmd.n_bits = DECODED_COMMAND_NBITS;
}
void sendRAWCommand(WORD * raw16) {
// we have to repeat packet like another IR-controllers do
byte count = 7;
while(count--) {
IR.send_raw16(raw16);
delay(30);
}
}
void sendVendorCommand(unsigned long cmd) {
// we have to repeat packet like another IR-controllers do
byte count = 7;
while(count--) {
vendor_cmd.data[0] = cmd;
IR.sendCommand(&vendor_cmd);
delay(30);
}
}
void loop() {
...
}