Class HttpClient
IRDevice Class
Members
Public Constructors |
|
---|---|
A public constructor should not be used as this class is intended to be a singleton class. Access member functions using the object instance named IR. |
Public Methods |
|
---|---|
IRDevice::getFreq |
Get the current IR modulation frequency |
IRDevice::begin |
Allocate resources and start the IR device with a custom frequency |
IRDevice::end |
Stop the IR device operations and free up resources |
IRDevice::send |
Send IR raw data |
IRDevice::beginNEC |
Allocate resources and start the IR device with a frequency suitable for the NEC protocol |
IRDevice::sendNEC |
Send data using the NEC protocol |
IRDevice::recvNEC |
Receive data using the NEC protocol |
IRDevice::getFreq
IRDevice::begin
IRDevice::end
IRDevice::send
Example Code
#include “IRDevice.h”
// User defined txPin, rxPin and carrier frequency
#define IR_RX_PIN 8
#define IR_TX_PIN 9
#define CARRIER_FREQ 38000
unsigned int irRawSignal[] = {
9000, 4500, // starting bit
560, 560, 560, 560, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, // address 00100000 : 4
560, 1690, 560, 1690, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 1690, // ~ address 11011111
560, 560, 560, 560, 560, 560, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 560, // data 00010000 : 8
560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 1690, //~ data 11101111
560 // stoping bit
};
int DataLen = sizeof(irRawSignal) / sizeof(irRawSignal[0]); // 284/ 4 = 71
void setup()
{
Serial.begin(115200);
IR.begin(IR_RX_PIN, IR_TX_PIN, IR_MODE_TX, CARRIER_FREQ);
}
void loop()
{
IR.send(irRawSignal, DataLen);
Serial.println(“Finished Sending NEC Raw Data….”);
delay(3000);
}
IRDevice::beginNEC
#include “IRDevice.h”
uint8_t adr = 0;
uint8_t cmd = 0;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
IR.beginNEC(8, 9, IR_MODE_RX); // configure for NEC IR protocol
}
void loop() {
if (IR.recvNEC(adr, cmd, 1000)) {
Serial.print(“Received “);
Serial.print(adr);
Serial.print(cmd);
Serial.println();
} else {
Serial.println(“Received nothing, timed out”);
}
//IR.end();
}
IRDevice::sendNEC
#include “IRDevice.h”
uint8_t adr = 0;
uint8_t cmd = 0;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
IR.beginNEC(8, 9, IR_MODE_TX); // configure for NEC IR protocol
}
void loop() {
if (cmd++ >=255) {
adr++;
}
IR.sendNEC(adr, cmd);
Serial.print(“Sent “);
Serial.print(adr);
Serial.print(cmd);
Serial.println();
//IR.end(); // Call this method to stop IR device and free up the pins for other uses
}
IRDevice::recvNEC