Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mrtheduke/c147425ce0e491d117a8bb7ec0f524a7 to your computer and use it in GitHub Desktop.
Save mrtheduke/c147425ce0e491d117a8bb7ec0f524a7 to your computer and use it in GitHub Desktop.
IR Remote Fails With Variables
// IRremote - Version: Latest
#include <IRremote.h>
const byte numChars = 32;
char receivedChars[numChars];
char recType = 'n';
boolean newData = false;
void setup() {
Serial.begin(9600);
Serial.println("<Arduino is ready>");
}
void loop() {
recvWithStartEndMarkers();
if (recType == 'p'){
sendPanasonic();
}
else if (recType == 'h'){
sendRaw();
}
}
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char panMarker = '<';
char humMarker = '(';
char endMarker = '>';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == panMarker) {
recType = 'p';
recvInProgress = true;
}
else if (rc == humMarker) {
recType = 'h';
recvInProgress = true;
}
}
}
void sendPanasonic() {
if (newData == true) {
Serial.print("Panasonic ");
Serial.println(receivedChars);
#define PanasonicAddress 0x4004 // Panasonic address (Pre data)
#define PanasonicPower receivedChars // Panasonic Power button
IRsend irsend;
irsend.sendPanasonic(PanasonicAddress,receivedChars);
newData = false;
}
}
void sendRaw() {
if (newData == true) {
IRsend irsend;
Serial.print("Humax ");
Serial.println(receivedChars);
int khz = 38; // 38kHz carrier frequency for the NEC protocol
unsigned int irSignal[] = {receivedChars};
irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
newData = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment