Commit 7f14d67d authored by Jari Suominen's avatar Jari Suominen

ha

parent 457a6703
/* IRLibRData.h from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.5 June 2014
/* IRLib.cpp from IRLib - an Arduino library for infrared encoding and decoding
* Version 1.51 March 2015
* Copyright 2014 by Chris Young http://cyborg5.com
*
* This library is a major rewrite of IRemote by Ken Shirriff which was covered by
......@@ -27,28 +27,56 @@
* Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
*/
#ifndef IRLibRData_h
#define IRLibRData_h
/*
* The structure contains a variety of variables needed by the receiver routines.
* Typically this data would be part of the IRrecv class however the interrupt service routine
* must have access to it and you cannot pass a parameter to such a routine. The data must be global.
* You need not include this file unless you are creating a custom receiver class or extending
* the provided IRrecv class.
*/
#include <Arduino.h>
#include "IRBot.h"
const long IRBot::codes[] = {
0xFF728D,
0xFF7A85,
0xFFBA45,
0xFF7887,
0xFF52AD,
0xFF926D,
0xFF50AF,
0xFF5AA5,
0xFF9A65,
0xFF58A7
};
void IRBot::walk() {
pinMode(6,OUTPUT);
digitalWrite(6,HIGH);
delay(500);
analogWrite(6,100);
}
void IRBot::stop() {
digitalWrite(6,LOW);
}
void IRBot::sendIR(int code) {
pinMode(5,OUTPUT);
digitalWrite(5,LOW);
mySender.send(NEC,codes[code],32);
}
void IRBot::waitIR(int code) {
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
digitalWrite(9,HIGH);
digitalWrite(10,LOW);
myReceiver.enableIRIn();
while (true) {
if (myReceiver.GetResults(&myDecoder)) {
myDecoder.decode();
if (myDecoder.value==codes[code])
return;
myReceiver.resume();
}
}
}
// receiver states
enum rcvstate_t {STATE_UNKNOWN, STATE_IDLE, STATE_MARK, STATE_SPACE, STATE_STOP, STATE_RUNNING};
// information for the interrupt handler
typedef struct {
unsigned char recvpin; // pin for IR data from detector
rcvstate_t rcvstate; // state machine
bool blinkflag; // TRUE to enable blinking of pin 13 on IR processing
unsigned long timer; // state timer, counts 50uS ticks.(and other uses)
unsigned int rawbuf[RAWBUF]; // raw data
unsigned char rawlen; // counter of entries in rawbuf
}
irparams_t;
extern volatile irparams_t irparams;
#endif
/* IRLibMatch.h from IRLib an Arduino library for infrared encoding and decoding
* Version 1.5 June 2014
/* IRLib.h from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.51 March 2015
* Copyright 2014 by Chris Young http://cyborg5.com
*
* This library is a major rewrite of IRemote by Ken Shirriff which was covered by
......@@ -27,74 +27,27 @@
* Also influenced by http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/
*/
#ifndef IRLibMatch_h
#define IRLibMatch_h
#ifndef IRBot_h
#define IRBot_h
#include <Arduino.h>
#include "../IRLib/IRLib.h"
/*
* Originally all timing comparisons for decoding were based on a percent of the
* target value. However when target values are relatively large, the percent tolerance
* is too much. In some instances an absolute tolerance is needed. In order to maintain
* backward compatibility, the default will be to continue to use percent. If you wish to default
* to an absolute tolerance, you should comment out the line below.
*/
#define IRLIB_USE_PERCENT
/*
* These are some miscellaneous definitions that are needed by the decoding routines.
* You need not include this file unless you are creating custom decode routines
* which will require these macros and definitions. Even if you include it, you probably
* don't need to be intimately familiar with the internal details.
*/
#define USECPERTICK 50 // microseconds per clock interrupt tick
#define PERCENT_TOLERANCE 25 // percent tolerance in measurements
#define DEFAULT_ABS_TOLERANCE 75 //absolute tolerance in microseconds
/*
* These revised MATCH routines allow you to use either percentage or absolute tolerances.
* Use ABS_MATCH for absolute and PERC_MATCH for percentages. The original MATCH macro
* is controlled by the IRLIB_USE_PERCENT definition a few lines above.
*/
#define PERCENT_LOW(us) (unsigned int) (((us)*(1.0 - PERCENT_TOLERANCE/100.)))
#define PERCENT_HIGH(us) (unsigned int) (((us)*(1.0 + PERCENT_TOLERANCE/100.) + 1))
#define ABS_MATCH(v,e,t) ((v) >= ((e)-(t)) && (v) <= ((e)+(t)))
#define PERC_MATCH(v,e) ((v) >= PERCENT_LOW(e) && (v) <= PERCENT_HIGH(e))
#ifdef IRLIB_USE_PERCENT
#define MATCH(v,e) PERC_MATCH(v,e)
#else
#define MATCH(v,e) ABS_MATCH(v,e,DEFAULT_ABS_TOLERANCE)
#endif
class IRBot
{
public:
IRBot() : myReceiver(11) {};
void walk();
void stop();
void waitIR(int code);
void sendIR(int code);
//The following two routines are no longer necessary because mark/space adjustments are done elsewhere
//These definitions maintain backward compatibility.
#define MATCH_MARK(t,u) MATCH(t,u)
#define MATCH_SPACE(t,u) MATCH(t,u)
IRrecv myReceiver;
IRdecode myDecoder;
IRsend mySender;
#ifdef IRLIB_TRACE
void IRLIB_ATTEMPT_MESSAGE(const __FlashStringHelper * s);
void IRLIB_TRACE_MESSAGE(const __FlashStringHelper * s);
byte IRLIB_REJECTION_MESSAGE(const __FlashStringHelper * s);
byte IRLIB_DATA_ERROR_MESSAGE(const __FlashStringHelper * s, unsigned char index, unsigned int value, unsigned int expected);
#define RAW_COUNT_ERROR IRLIB_REJECTION_MESSAGE(F("number of raw samples"));
#define HEADER_MARK_ERROR(expected) IRLIB_DATA_ERROR_MESSAGE(F("header mark"),offset,rawbuf[offset],expected);
#define HEADER_SPACE_ERROR(expected) IRLIB_DATA_ERROR_MESSAGE(F("header space"),offset,rawbuf[offset],expected);
#define DATA_MARK_ERROR(expected) IRLIB_DATA_ERROR_MESSAGE(F("data mark"),offset,rawbuf[offset],expected);
#define DATA_SPACE_ERROR(expected) IRLIB_DATA_ERROR_MESSAGE(F("data space"),offset,rawbuf[offset],expected);
#define TRAILER_BIT_ERROR(expected) IRLIB_DATA_ERROR_MESSAGE(F("RC5/RC6 trailer bit length"),offset,rawbuf[offset],expected);
#else
#define IRLIB_ATTEMPT_MESSAGE(s)
#define IRLIB_TRACE_MESSAGE(s)
#define IRLIB_REJECTION_MESSAGE(s) false
#define IRLIB_DATA_ERROR_MESSAGE(s,i,v,e) false
#define RAW_COUNT_ERROR false
#define HEADER_MARK_ERROR(expected) false
#define HEADER_SPACE_ERROR(expected) false
#define DATA_MARK_ERROR(expected) false
#define DATA_SPACE_ERROR(expected) false
#define TRAILER_BIT_ERROR(expected) false
#endif
const static long codes[];
};
#endif //IRLibMatch_h
#endif //IRLib_h
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.4 March 2014
* Copyright 2014 by Chris Young http://cyborg5.com
* Based on original example sketch for IRremote library
* Version 0.11 September, 2009I know prescription and no
* Copyright 2009 Ken Shirriff
* http://www.righto.com/
*/
/*
* This example demonstrates how to extend this library to add a new protocol
* without actually modifying or recompiling the library itself. It implements the protocol
* used by DirecTV. This protocol actually comes in six different varieties.
* It uses three different frequencies 38, 40, or 57 kHz. It also uses two different varieties
* lead out times either 9000us or 30000us. The default is 38 kHz and 30000us.
* You can use a different constructor for the other varieties.
* This is a modified version of the IRecord example.
* If you would like to make this a permanent part of your library you could copy the class
* prototypes to IRLib.h and the code itself to IRLib.cpp. Search for the word "ADDITIONAL"
* to see where to add various pieces of code. Also see the Samsung36 example for details.
*/
#include <IRLib.h>
#include <IRLibMatch.h>
class IRdecodeDirecTV: public virtual IRdecodeBase
{
public:
bool decode(void);
bool Repeat;
};
class IRsendDirecTV: public virtual IRsendBase
{
public:
IRsendDirecTV (int khz= 38,bool LongLeadOut=true);
void send(unsigned long data, bool Repeat);
int Freq;
unsigned int LeadOut;
};
#define DIRECTV (LAST_PROTOCOL+1)
/*
* According to http://www.hifi-remote.com/johnsfine/DecodeIR.html#DirecTV
* The IRP notation for this protocol is:
*{38k,600,msb}<1,-1|1,-2|2,-1|2,-2>(5,(5,-2,D:4,F:8,C:4,1,-50)+) {C=7*(F:2:6)+5*(F:2:4)+3*(F:2:2)+(F:2)}
* Unlike most protocols which use a fixed length mark and a variable length or a variable length
* mark a fixed length space, this protocol varies both the mark and the space.
* The stream is still a series of marks and spaces but the length of either of those
* denotes a one or zero. A length of 1200us=logical 1 and length 600us=logical 0
* It also makes changes to the length of the header mark to devote repeat codes.
* The first header mark should be 6000us but repeat codes should only be 3000us.
*/
bool IRdecodeDirecTV::decode(void) {
long data; int offset;
IRLIB_ATTEMPT_MESSAGE(F("DirecTV"));
if (rawlen != 20) return RAW_COUNT_ERROR;
if (MATCH(rawbuf[1],3000))
Repeat=true;
else
if (!MATCH(rawbuf[1],6000)){
return HEADER_MARK_ERROR(6000);
} else {
Repeat=false;
}
if (!MATCH(rawbuf[2],1200)) return HEADER_SPACE_ERROR(1200);
offset=3; data=0;
while (offset < 18) {
if (MATCH(rawbuf[offset],1200)) {
data = (data << 1) | 1;
}
else if (MATCH(rawbuf[offset],600)) {
data <<= 1;
}
else return DATA_MARK_ERROR(1200);
offset++;
if (MATCH(rawbuf[offset],1200)) {
data = (data << 1) | 1;
}
else if (MATCH (rawbuf[offset],600)) {
data <<= 1;
}
else return DATA_SPACE_ERROR(1200);
offset++;
}
if (!MATCH(rawbuf[1],6000)) return DATA_MARK_ERROR(6000);
bits = 16;//set bit length
value = data;//put remaining bits in value
decode_type= static_cast<IRTYPES>DIRECTV;
return true;
};
//See the comment at the top about different frequencies and lead out times
IRsendDirecTV::IRsendDirecTV (int khz, bool LongLeadOut){
Freq=khz;
if (LongLeadOut) LeadOut=50*600; else LeadOut=15*600;
};
void IRsendDirecTV::send(unsigned long data, bool Repeat) {
enableIROut(Freq);
if(Repeat) mark(3000); else mark(6000);
space(1200);//Send header
for (int i = 0; i < 8; i++) {
if (data & 0x8000) mark(1200); else mark(600);
data <<= 1;
if (data & 0x8000) space(1200); else space(600);
data <<= 1;
};
mark(600);
space(LeadOut);
};
//Create a custom class that combines this new protocol with all the others
class MyCustomSend:
public virtual IRsend,
public virtual IRsendDirecTV
{
public:
void send(IRTYPES Type, unsigned long data, int nbits);
};
void MyCustomSend::send(IRTYPES Type, unsigned long data, int nbits) {
if (Type==DIRECTV)
IRsendDirecTV::send(data,false);
else
IRsend::send(Type, data, nbits);
}
class MyCustomDecode:
public virtual IRdecode,
public virtual IRdecodeDirecTV
{
public:
virtual bool decode(void); // Calls each decode routine individually
void DumpResults(void);
};
bool MyCustomDecode::decode(void) {
if (IRdecodeDirecTV::decode()) return true;
return IRdecode::decode ();
}
void MyCustomDecode::DumpResults(void){
if(decode_type==DIRECTV) {
Serial.print(F("Decoded DirecTV: Value:")); Serial.print(value, HEX);
if (Repeat) Serial.print(F(" repeat flag"));
};
IRdecode::DumpResults();
};
MyCustomDecode My_Decoder;
MyCustomSend My_Sender;
int RECV_PIN = 11;
IRrecv My_Receiver(RECV_PIN);
IRTYPES codeType; // The type of code
unsigned long codeValue; // The data bits
int codeBits; // The length of the code in bits
bool GotOne;
void setup()
{
GotOne=false;
codeType=UNKNOWN;
codeValue=0;
codeBits=0;
Serial.begin(9600);
Serial.println(F("Send a code from your remote and we will record it."));
Serial.println(F("Type any character and press enter. We will send the recorded code."));
My_Receiver.enableIRIn(); // Start the receiver
}
void loop() {
if (Serial.available()>0) {
unsigned char c=Serial.read();
if (c=='p') {//Send a test pattern
GotOne= true; codeType=DIRECTV; codeValue=0x1234; codeBits=16;
}
if(GotOne) {
My_Sender.send(codeType,codeValue,codeBits);
Serial.print(F("Sent "));
if (codeType== DIRECTV) Serial.print(F("DirecTV")); else Serial.print(Pnames(codeType));
Serial.print(F(" Value:0x"));
Serial.print(codeValue, HEX);
Serial.print(F(" Bits:"));
Serial.println(codeBits, DEC);
My_Receiver.enableIRIn(); // Re-enable receiver
}
}
else if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode();
if(My_Decoder.decode_type == UNKNOWN) {
Serial.println(F("Unknown type received. Ignoring."));
} else {
codeType= My_Decoder.decode_type;
codeValue= My_Decoder.value;
codeBits= My_Decoder.bits;
GotOne=true;
}
My_Decoder.DumpResults();
delay(1000);
My_Receiver.resume();
}
}
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.4 March 2014
* Copyright 2014 by Chris Young http://cyborg5.com
* Based on original example sketch for IRremote library
* Version 0.11 September, 2009I know prescription and no
* Copyright 2009 Ken Shirriff
* http://www.righto.com/
*/
/*
* This example demonstrates how to extend this library to add a new protocol
* without actually modifying or recompiling the library itself. It implements the protocol
* known as GIcable which is used by some Motorola cable boxes.
* This is a modified version of the IRecord example.
* If you would like to make this a permanent part of your library you could copy the class
* prototypes to IRLib.h and the code itself to IRLib.cpp. Search for the word "ADDITIONAL"
* to see where to add various pieces of code. Also see the Samsung36 example for details.
*/
#include <IRLib.h>
#include <IRLibMatch.h>
class IRdecodeGIcable: public virtual IRdecodeBase
{
public:
bool decode(void);
};
class IRsendGIcable: public virtual IRsendBase
{
public:
void send(unsigned long data, bool Repeat);
};
#define GICABLE (LAST_PROTOCOL+1)
/* The IRP notation for this protocol according to
* http://www.hifi-remote.com/johnsfine/DecodeIR.html#G.I. Cable
* is "{38.7k,490}<1,-4.5|1,-9>(18,-9,F:8,D:4,C:4,1,-84,(18,-4.5,1,-178)*) {C = -(D + F:4 + F:4:4)}"
*/
bool IRdecodeGIcable::decode(void) {
IRLIB_ATTEMPT_MESSAGE(F("GIcable"));
// Check for repeat
if (rawlen == 4 && MATCH(rawbuf[1], 490*18) && MATCH(rawbuf[2],2205)) {
bits = 0;
value = REPEAT;
decode_type= static_cast<IRTYPES>GICABLE;
return true;
}
if(!decodeGeneric(36, 18*490, 9*490, 0, 490, 9*490, 2205/*(4.5*490)*/)) return false;
decode_type= static_cast<IRTYPES>GICABLE;
return true;
};
void IRsendGIcable::send(unsigned long data, bool Repeat) {
if(Repeat) {
enableIROut(39);
mark (490*18); space (2205); mark (490); space(220);delay (87);//actually "space(87200);"
} else {
sendGeneric(data,16, 490*18, 490*9, 490, 490, 490*9, 2205, 39, true);
}
};
//Create a custom class that combines this new protocol with all the others
class MyCustomSend:
public virtual IRsend,
public virtual IRsendGIcable
{
public:
void send(IRTYPES Type, unsigned long data, int nbits);
};
void MyCustomSend::send(IRTYPES Type, unsigned long data, int nbits) {
if (Type==GICABLE){
IRsendGIcable::send(data,false);
//un-comment the line below to text repeats
//delay(3000); IRsendGIcable::send(data,true);
}
else
IRsend::send(Type, data, nbits);
}
class MyCustomDecode:
public virtual IRdecode,
public virtual IRdecodeGIcable
{
public:
virtual bool decode(void); // Calls each decode routine individually
void DumpResults(void);
};
bool MyCustomDecode::decode(void) {
if (IRdecodeGIcable::decode()) return true;
return IRdecode::decode ();
}
void MyCustomDecode::DumpResults(void){
if(decode_type==GICABLE) {
Serial.print(F("Decoded GIcable: Value:")); Serial.print(value, HEX);
};
IRdecode::DumpResults();
};
MyCustomDecode My_Decoder;
MyCustomSend My_Sender;
int RECV_PIN =11;
IRrecv My_Receiver(RECV_PIN);
IRTYPES codeType; // The type of code
unsigned long codeValue; // The data bits
int codeBits; // The length of the code in bits
bool GotOne;
void setup()
{
GotOne=false;
codeType=UNKNOWN;
codeValue=0;
codeBits=0;
Serial.begin(9600);
Serial.println(F("Send a code from your remote and we will record it."));
Serial.println(F("Type any character and press enter. We will send the recorded code."));
My_Receiver.enableIRIn(); // Start the receiver
}
void loop() {
if (Serial.available()>0) {
unsigned char c=Serial.read();
if (c=='p') {//Send a test pattern
GotOne= true; codeType=GICABLE; codeValue=0x1234; codeBits=16;
}
if(GotOne) {
My_Sender.send(codeType,codeValue,codeBits);
Serial.print(F("Sent "));
if (codeType== GICABLE) Serial.print(F("GIcable")); else Serial.print(Pnames(codeType));
Serial.print(F(" Value:0x"));
Serial.print(codeValue, HEX);
Serial.print(F(" Bits:"));
Serial.println(codeBits, DEC);
My_Receiver.enableIRIn(); // Re-enable receiver
}
}
else if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode();
if(My_Decoder.decode_type == UNKNOWN) {
Serial.println(F("Unknown type received. Ignoring."));
} else {
codeType= My_Decoder.decode_type;
codeValue= My_Decoder.value;
codeBits= My_Decoder.bits;
GotOne=true;
}
My_Decoder.DumpResults();
delay(1000);
My_Receiver.resume();
}
}
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.3 January 2014
* Copyright 2014 by Chris Young http://cyborg5.com
* Based on original example sketch for IRremote library
* Version 0.11 September, 2009
* Copyright 2009 Ken Shirriff
* http://www.righto.com/
*/
/* IRanalyze receives repeated values from a remote and averages the results. Should help in
* analyzing unknown protocols. You have to press the same key repeatedly. If you press a
* different key the totals reset and it computes new averages.
*/
#include <IRLib.h>
#include <IRLibRData.h>
int RECV_PIN = 11;
unsigned int Samples,i, LowSpace, LowMark, HighMark, HighSpace, interval,
balm,aalm,bahm,aahm,bals,aals,bahs,aahs;
unsigned char bacm,aacm,bacs,aacs, Mark_Count,Space_Count;
unsigned int Accumulated_Time[RAWBUF];
unsigned long Mark_Avg, Space_Avg,baam,aaam,baas,aaas;
//Try this program with various receivers
IRrecv My_Receiver(RECV_PIN);
//IRrecvLoop My_Receiver(RECV_PIN);
//Use interrupt=0. This is pin 2 on Arduino Uno and Mega, pin 3 on Leonardo
//IRrecvPCI My_Receiver(0);
IRdecode My_Decoder;
IRTYPES Old_Type;
unsigned long Old_Value;
void setup()
{
Serial.begin(9600);
delay(1000);while(!Serial);
My_Receiver.enableIRIn();
// My_Receiver.Mark_Excess=50;//Try different values here
Samples=0;Old_Value=0; Old_Type=UNKNOWN;
Serial.println(F("Send a signal repeatedly. We will report averages and statistics."));
}
void Tab(void) {Serial.print("\t");};
void loop() {
if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode();
if( (My_Decoder.decode_type != Old_Type) || (My_Decoder.value != Old_Value)) {
Serial.println(F("Resetting counters"));
for(i=0;i<RAWBUF;i++) {
Accumulated_Time[i]=0;
};
Samples=0;Old_Value= My_Decoder.value; Old_Type=My_Decoder.decode_type;
};
Samples++;
Serial.print(F("\nSamples=")); Serial.println(Samples,DEC);
LowSpace = LowMark=65535;
HighSpace = HighMark=0;
Mark_Avg= Space_Avg= Mark_Count= Space_Count=0;
for(i=0;i<My_Decoder.rawlen;i++){
Accumulated_Time[i]+=My_Decoder.rawbuf[i];
My_Decoder.rawbuf[i]= Accumulated_Time[i]/Samples;//Put back average so DumpResults can report
}
My_Decoder.DumpResults();
//Perform additional analysis
for(i=3;i<My_Decoder.rawlen;i++){ //Compute low, high and average mark and space
interval=My_Decoder.rawbuf[i];
if(i % 2) {
Mark_Avg += interval; LowMark=min(LowMark, interval); HighMark=max(HighMark, interval);Mark_Count++;
} else {
Space_Avg += interval; LowSpace=min(LowSpace, interval); HighSpace=max (HighSpace, interval);Space_Count++;
}
My_Decoder.rawbuf[i]= Accumulated_Time[i]/Samples;//Put back average so DumpResults can report
}
Mark_Avg /= Mark_Count; Space_Avg /= Space_Count;
//Now compute below average highs and lows and above average highs and lows
balm=bals=aalm=aals=32766;
bahm=bahs=aahm=aahs=baam=baas=aaam=aaas=0;
bacm=bacs=aacm=aacs=0;
for(i=3;i<My_Decoder.rawlen;i++){
interval=My_Decoder.rawbuf[i];
if(i % 2) {
if (interval>Mark_Avg) {
aalm=min(aalm,interval); aahm=max(aahm,interval);aacm++;aaam+=interval;
} else {
balm=min(balm,interval); bahm=max(bahm,interval);bacm++;baam+=interval;
}
} else {
if (interval>Space_Avg) {
aals=min(aals,interval); aahs=max(aahs,interval);aacs++;aaas+=interval;
} else {
bals=min(bals,interval); bahs=max(bahs,interval);bacs++;baas+=interval;
}
}
}
baam/=bacm;baas/=bacs;aaam/=aacm;aaas/=aacs;
Serial.println(F("\t #\tLow\tHigh\tAvg."));
Serial.print(F("Mark\t"));Serial.print(Mark_Count,DEC);Tab();Serial.print(LowMark,DEC);Tab();Serial.print(HighMark,DEC);Tab();Serial.println(Mark_Avg,DEC);
Serial.print(F("Space\t"));Serial.print(Space_Count,DEC);Tab();Serial.print(LowSpace,DEC);Tab();Serial.print(HighSpace,DEC);Tab();Serial.println(Space_Avg,DEC);
Serial.println(F("\nMarks\t\t #\tLow\tHigh\tAvg."));
Serial.print(F("Above Avg\t"));Serial.print(aacm,DEC);Tab();Serial.print(aalm,DEC);Tab();Serial.print(aahm,DEC);Tab();Serial.println(aaam,DEC);
Serial.print(F("Belows Avg.\t"));Serial.print(bacm,DEC);Tab();Serial.print(balm,DEC);Tab();Serial.print(bahm,DEC);Tab();Serial.println(baam,DEC);
Serial.println(F("\nSpaces\t\t #\tLow\tHigh\tAvg."));
Serial.print(F("Above Avg.\t"));Serial.print(aacs,DEC);Tab();Serial.print(aals,DEC);Tab();Serial.print(aahs,DEC);Tab();Serial.println(aaas,DEC);
Serial.print(F("Below Avg.\t"));Serial.print(bacs,DEC);Tab();Serial.print(bals,DEC);Tab();Serial.print(bahs,DEC);Tab();Serial.println(baas,DEC);
#define RATIO(n,d) Tab(); Serial.print(float(n)/float(d));
Serial.print(F("\nRatios\t\tBelow\tAbove\n"));
Serial.print(F("Head Mark"));RATIO(My_Decoder.rawbuf[1],baam);RATIO(My_Decoder.rawbuf[1],aaam);
Serial.print(F("\nHead Space"));RATIO(My_Decoder.rawbuf[2],baas);RATIO(My_Decoder.rawbuf[2],aaas);
Serial.print(F("\n\nMark Above/Below="));RATIO(aaam,baam);
Serial.print(F("\nSpace Above/Below="));RATIO(aaas,baas);
Serial.println();
delay(500);
My_Receiver.resume();
};
}
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.5 June 2014
* Copyright 2014 by Chris Young http://tech.cyborg5.com
* Based on Arduino firmware for use with AnalysIR IR signal analysis
* software for Windows PCs. Many thanks to the people
* at http://analysir.com for their assistance In developing this program.
*/
/*
* IRLib: IRfreq - dump details of IR codes with IRrecvPCI and
* measures frequency using IRfrequency. You must connect an IR learner
* such as TSMP58000 to a hardware interrupt pin.
*/
#include <IRLib.h>
#define FREQUENCY_INTERRUPT 0
IRfrequency My_Freq(FREQUENCY_INTERRUPT);
void setup()
{
Serial.begin(9600);
delay(2000);while(!Serial);//delay for Leonardo
Serial.print(F("Interrupt="));Serial.print(FREQUENCY_INTERRUPT,DEC);
Serial.print(F(" Pin=")); Serial.println(My_Freq.getPinNum(),DEC);
if(My_Freq.getPinNum()==255)
Serial.println(F("Invalid interrupt number."));
My_Freq.enableFreqDetect();//starts interrupt routine to compute frequency
}
void loop() {
if (My_Freq.HaveData()) {
delay(500); //it couldn't hurt to collect a little more just in case
My_Freq.disableFreqDetect();
My_Freq.DumpResults(false);//Change to "true" for more detail
My_Freq.enableFreqDetect();//Zero out previous results and restart YSR
}
}
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding