void print()
{
Serial.println();
}
template <typename T>
void print(T input)
{
Serial.println(input);
}
template <typename T, typename... Args>
void print(T input, Args... other)
{
Serial.print(input);
print(other...);
}
class IRremote
{
private:
bool isAvailable = true;
int irPin;
public:
void begin(int pin)
{
irPin = pin;
pinMode(irPin,INPUT);
isAvailable = false;
}
bool available()
{
unsigned long startPulse = pulseIn(irPin, LOW, 1000000);
//Serial.println(startPulse);
print("startPulse : ",startPulse);
if(startPulse > 8000 && startPulse < 10000)
{
// unsigned long startGap = pulseIn(irPin, HIGH, 1000000);
// print("startGap : ",startGap);
// if(startGap > 300 && startGap < 5000)
// {
// //print("available!!!!!");
// isAvailable = true;
// }
isAvailable = true;
}
return isAvailable;
}
unsigned long read()
{
unsigned long irData = 0;
while(true)
{
}
isAvailable = false;
return irData;
}
};
IRremote remote;
#define IR_PIN 2
void setup()
{
Serial.begin(9600);
Serial.println("starting...");
remote.begin(IR_PIN);
}
void loop()
{
unsigned long startPulse = pulseIn(IR_PIN,LOW,1000000);
if(startPulse > 8000)
{
Serial.print("Start LOW: ");
Serial.println(startPulse);
unsigned long startGap = pulseIn(IR_PIN, HIGH, 1000000);
Serial.print("Start HIGH: ");
Serial.println(startGap);
for (int i = 0; i < 10; i++) { // Just first 10 bits for debugging
unsigned long lowPulse = pulseIn(IR_PIN, LOW, 1000000);
unsigned long highPulse = pulseIn(IR_PIN, HIGH, 1000000);
Serial.print("Bit ");
Serial.print(i);
Serial.print(" - LOW: ");
Serial.print(lowPulse);
Serial.print(" HIGH: ");
Serial.println(highPulse);
}
}
}