A
Arduino_ATmega8
- 20 Дек 2016
Привет!
Долго рыл интернет, чтобы запихать библиотеку IRremote в мегу8, с 8 кб памяти. Наконец нашел способ!
В библиотеке есть Файл IRremote.h
Удаляем из него все не нужные пульты, кроме той модели что будет использоваться для управления и сохраняем. После этих действий скетч влезет в 8 мегу!)
В чем плюс её использование- код становится до безобразия простой, не нужно настраивать регистра меги!
Может кому пригодится!
#include <IRremote.h>
int RECV_PIN = 2; //вход ИК приемника
IRrecv irrecv(RECV_PIN);
decode_results results;
int LED = 9;
void setup()
{
irrecv.enableIRIn(); // включить приемник
pinMode(LED, OUTPUT);
}
void loop() {
if (irrecv.decode(&results))
{
if (results.value == 0x20DF8E7) //код моей кнопки "2FD807F". У Вас он будет дугой
{
digitalWrite(LED, HIGH);
}
if (results.value == 0x20DF4EB)//код моей кнопки "2FD40BF". У Вас он будет дугой
{
digitalWrite(LED, LOW);
}
irrecv.resume();
}
}
Измененный файл (в этом примере под пульт от LG & RC5-6)
//******************************************************************************
// IRremote
// Version 2.0.1 June, 2015
// Copyright 2009 Ken Shirriff
// For details, see ссылка скрыта от гостей
// Edited by Mitra to add new controller SANYO
//
// Interrupt code based on NECIRrcv by Joe Knapp
// ссылка скрыта от гостей
// Also influenced by ссылка скрыта от гостей /
//
// JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
// LG added by Darryl Smith (based on the JVC protocol)
// Whynter A/C ARC-110WD added by Francesco Meschia
//******************************************************************************
#ifndef IRremote_h
#define IRremote_h
//------------------------------------------------------------------------------
// The ISR header contains several useful macros the user may wish to use
//
#include "IRremoteInt.h"
//------------------------------------------------------------------------------
// Supported IR protocols
// Each protocol you include costs memory and, during decode, costs time
// Disable (set to 0) all the protocols you do not need/want!
//
#define DECODE_RC5 1
#define SEND_RC5 1
#define DECODE_RC6 1
#define SEND_RC6 1
#define DECODE_LG 1
#define SEND_LG 1
//
#define PRONTO_ONCE false
#define PRONTO_REPEAT true
#define PRONTO_FALLBACK true
#define PRONTO_NOFALLBACK false
//------------------------------------------------------------------------------
// An enumerated list of all supported formats
// You do NOT need to remove entries from this list when disabling protocols!
//
typedef
enum {
UNKNOWN = -1,
UNUSED = 0,
RC5,
RC6,
LG,
}
decode_type_t;
//------------------------------------------------------------------------------
// Set DEBUG to 1 for lots of lovely debug output
//
#define DEBUG 0
//------------------------------------------------------------------------------
// Debug directives
//
#if DEBUG
# define DBG_PRINT(...) Serial.print(__VA_ARGS__)
# define DBG_PRINTLN(...) Serial.println(__VA_ARGS__)
#else
# define DBG_PRINT(...)
# define DBG_PRINTLN(...)
#endif
//------------------------------------------------------------------------------
// Mark & Space matching functions
//
int MATCH (int measured, int desired) ;
int MATCH_MARK (int measured_ticks, int desired_us) ;
int MATCH_SPACE (int measured_ticks, int desired_us) ;
//------------------------------------------------------------------------------
// Results returned from the decoder
//
class decode_results
{
public:
decode_type_t decode_type; // UNKNOWN, NEC, SONY, RC5, ...
unsigned int address; // Used by Panasonic & Sharp [16-bits]
unsigned long value; // Decoded value [max 32-bits]
int bits; // Number of bits in decoded value
volatile unsigned int *rawbuf; // Raw intervals in 50uS ticks
int rawlen; // Number of records in rawbuf
int overflow; // true iff IR raw code too long
};
//------------------------------------------------------------------------------
// Decoded value for NEC when a repeat code is received
//
#define REPEAT 0xFFFFFFFF
//------------------------------------------------------------------------------
// Main class for receiving IR
//
class IRrecv
{
public:
IRrecv (int recvpin) ;
IRrecv (int recvpin, int blinkpin);
void blink13 (int blinkflag) ;
int decode (decode_results *results) ;
void enableIRIn ( ) ;
bool isIdle ( ) ;
void resume ( ) ;
private:
long decodeHash (decode_results *results) ;
int compare (unsigned int oldval, unsigned int newval) ;
//......................................................................
# if (DECODE_RC5 || DECODE_RC6)
// This helper function is shared by RC5 and RC6
int getRClevel (decode_results *results, int *offset, int *used, int t1) ;
# endif
# if DECODE_RC5
bool decodeRC5 (decode_results *results) ;
# endif
# if DECODE_RC6
bool decodeRC6 (decode_results *results) ;
# endif
//......................................................................
# if DECODE_LG
bool decodeLG (decode_results *results) ;
# endif
//......................................................................
} ;
//------------------------------------------------------------------------------
// Main class for sending IR
//
class IRsend
{
public:
IRsend () { }
void custom_delay_usec (unsigned long uSecs);
void enableIROut (int khz) ;
void mark (unsigned int usec) ;
void space (unsigned int usec) ;
void sendRaw (const unsigned int buf[], unsigned int len, unsigned int hz) ;
//......................................................................
# if SEND_RC5
void sendRC5 (unsigned long data, int nbits) ;
# endif
# if SEND_RC6
void sendRC6 (unsigned long data, int nbits) ;
# endif
# if SEND_LG
void sendLG (unsigned long data, int nbits) ;
# endif
} ;
#endif
ссылка скрыта от гостей
Долго рыл интернет, чтобы запихать библиотеку IRremote в мегу8, с 8 кб памяти. Наконец нашел способ!
В библиотеке есть Файл IRremote.h
Удаляем из него все не нужные пульты, кроме той модели что будет использоваться для управления и сохраняем. После этих действий скетч влезет в 8 мегу!)
В чем плюс её использование- код становится до безобразия простой, не нужно настраивать регистра меги!
Может кому пригодится!
#include <IRremote.h>
int RECV_PIN = 2; //вход ИК приемника
IRrecv irrecv(RECV_PIN);
decode_results results;
int LED = 9;
void setup()
{
irrecv.enableIRIn(); // включить приемник
pinMode(LED, OUTPUT);
}
void loop() {
if (irrecv.decode(&results))
{
if (results.value == 0x20DF8E7) //код моей кнопки "2FD807F". У Вас он будет дугой
{
digitalWrite(LED, HIGH);
}
if (results.value == 0x20DF4EB)//код моей кнопки "2FD40BF". У Вас он будет дугой
{
digitalWrite(LED, LOW);
}
irrecv.resume();
}
}
Измененный файл (в этом примере под пульт от LG & RC5-6)
//******************************************************************************
// IRremote
// Version 2.0.1 June, 2015
// Copyright 2009 Ken Shirriff
// For details, see ссылка скрыта от гостей
// Edited by Mitra to add new controller SANYO
//
// Interrupt code based on NECIRrcv by Joe Knapp
// ссылка скрыта от гостей
// Also influenced by ссылка скрыта от гостей /
//
// JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
// LG added by Darryl Smith (based on the JVC protocol)
// Whynter A/C ARC-110WD added by Francesco Meschia
//******************************************************************************
#ifndef IRremote_h
#define IRremote_h
//------------------------------------------------------------------------------
// The ISR header contains several useful macros the user may wish to use
//
#include "IRremoteInt.h"
//------------------------------------------------------------------------------
// Supported IR protocols
// Each protocol you include costs memory and, during decode, costs time
// Disable (set to 0) all the protocols you do not need/want!
//
#define DECODE_RC5 1
#define SEND_RC5 1
#define DECODE_RC6 1
#define SEND_RC6 1
#define DECODE_LG 1
#define SEND_LG 1
//
#define PRONTO_ONCE false
#define PRONTO_REPEAT true
#define PRONTO_FALLBACK true
#define PRONTO_NOFALLBACK false
//------------------------------------------------------------------------------
// An enumerated list of all supported formats
// You do NOT need to remove entries from this list when disabling protocols!
//
typedef
enum {
UNKNOWN = -1,
UNUSED = 0,
RC5,
RC6,
LG,
}
decode_type_t;
//------------------------------------------------------------------------------
// Set DEBUG to 1 for lots of lovely debug output
//
#define DEBUG 0
//------------------------------------------------------------------------------
// Debug directives
//
#if DEBUG
# define DBG_PRINT(...) Serial.print(__VA_ARGS__)
# define DBG_PRINTLN(...) Serial.println(__VA_ARGS__)
#else
# define DBG_PRINT(...)
# define DBG_PRINTLN(...)
#endif
//------------------------------------------------------------------------------
// Mark & Space matching functions
//
int MATCH (int measured, int desired) ;
int MATCH_MARK (int measured_ticks, int desired_us) ;
int MATCH_SPACE (int measured_ticks, int desired_us) ;
//------------------------------------------------------------------------------
// Results returned from the decoder
//
class decode_results
{
public:
decode_type_t decode_type; // UNKNOWN, NEC, SONY, RC5, ...
unsigned int address; // Used by Panasonic & Sharp [16-bits]
unsigned long value; // Decoded value [max 32-bits]
int bits; // Number of bits in decoded value
volatile unsigned int *rawbuf; // Raw intervals in 50uS ticks
int rawlen; // Number of records in rawbuf
int overflow; // true iff IR raw code too long
};
//------------------------------------------------------------------------------
// Decoded value for NEC when a repeat code is received
//
#define REPEAT 0xFFFFFFFF
//------------------------------------------------------------------------------
// Main class for receiving IR
//
class IRrecv
{
public:
IRrecv (int recvpin) ;
IRrecv (int recvpin, int blinkpin);
void blink13 (int blinkflag) ;
int decode (decode_results *results) ;
void enableIRIn ( ) ;
bool isIdle ( ) ;
void resume ( ) ;
private:
long decodeHash (decode_results *results) ;
int compare (unsigned int oldval, unsigned int newval) ;
//......................................................................
# if (DECODE_RC5 || DECODE_RC6)
// This helper function is shared by RC5 and RC6
int getRClevel (decode_results *results, int *offset, int *used, int t1) ;
# endif
# if DECODE_RC5
bool decodeRC5 (decode_results *results) ;
# endif
# if DECODE_RC6
bool decodeRC6 (decode_results *results) ;
# endif
//......................................................................
# if DECODE_LG
bool decodeLG (decode_results *results) ;
# endif
//......................................................................
} ;
//------------------------------------------------------------------------------
// Main class for sending IR
//
class IRsend
{
public:
IRsend () { }
void custom_delay_usec (unsigned long uSecs);
void enableIROut (int khz) ;
void mark (unsigned int usec) ;
void space (unsigned int usec) ;
void sendRaw (const unsigned int buf[], unsigned int len, unsigned int hz) ;
//......................................................................
# if SEND_RC5
void sendRC5 (unsigned long data, int nbits) ;
# endif
# if SEND_RC6
void sendRC6 (unsigned long data, int nbits) ;
# endif
# if SEND_LG
void sendLG (unsigned long data, int nbits) ;
# endif
} ;
#endif
ссылка скрыта от гостей