Hmm OK I can't seem to get any of the IR libraries to work but I figured out I can use pin 13 by using the pin change interrupts.
#define ENABLE_REMOTE
#include "remote.h"
#ifdef ENABLE_REMOTE
#include "Arduino.h"
#define RECV_PIN 13
static uint32_t nextCode = 0U;
#endif
void setupRemote() {
#ifdef ENABLE_REMOTE
pinMode(RECV_PIN, INPUT);
PCICR |= B00000001;
PCMSK0 |= B00100000;
#endif
}
uint32_t readRemote() {
#ifdef ENABLE_REMOTE
noInterrupts();
uint32_t result = nextCode;
nextCode = 0U;
interrupts();
return result;
#else
return 0U;
#endif
}
#ifdef ENABLE_REMOTE
ISR(PCINT0_vect) {
#define IR_BUFF_SIZE 32U
static uint32_t code = 0U;
static uint8_t count = 0U;
static uint32_t timeOfLast = 0U;
static bool wasPressed = false;
bool pressed = !digitalRead(RECV_PIN);
// If pin changed state
if (pressed != wasPressed) {
// If pin pressed.
if (pressed) {
uint32_t now = micros();
// Too long since last change, assume start of new code
if ((now - timeOfLast) > 10000) {
count = 0U;
code = 0U;
} else {
if ((now - timeOfLast) > 1680) {
code = code | (1L << count);
}
count++;
// If buffer full..
if (count >= IR_BUFF_SIZE) {
noInterrupts();
nextCode = code;
interrupts();
count = 0U;
code = 0U;
}
}
timeOfLast = now;
}
wasPressed = pressed;
}
}
#endif
Get something like this which I can use to figure out what button was pressed:
Button 1:
00:44:56.187 -> 4127723023
00:44:56.280 -> 4127723023
00:44:56.372 -> 4127723023
Button 2:
00:44:56.731 -> 4094299663
00:44:56.825 -> 4094299663
00:44:56.917 -> 4094299663
00:44:57.041 -> 4094299663
00:44:57.180 -> 4094299663
00:44:57.275 -> 4094299663
00:44:57.394 -> 4094299663
Button 3:
00:44:58.249 -> 4060876303
00:44:58.343 -> 4060876303
00:44:58.484 -> 4060876303
00:44:58.577 -> 4060876303
00:44:58.701 -> 4060876303
00:44:58.793 -> 4060876303
00:44:58.886 -> 4060876303
00:44:58.980 -> 4060876303