Hi there,
I run into compiling problem, I wish to use ATmega48V-10PU (4K Flash) with my sketch, I got this message:
Sketch uses 4162 bytes (101%) of program storage space. Maximum is 4096 bytes.
Global variables use 366 bytes (71%) of dynamic memory, leaving 146 bytes for local variables. Maximum is 512 bytes.
Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it.
Error compiling for board ATmega48 (no bootloader).
So, I already reduced my current code by 2% (before it was 103%), but I stuck, need to be reduced by 70 bytes more.
My Sketch:
#include "Wire.h"
#include "Keypad.h"
#define I2C_ADDR 0x1A
char pKey;
const byte nRows = 4;
const byte nCols = 4;
char kMap[nRows][nCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rPins[nRows] = {9,8,7,6};
byte cPins[nCols]= {5,4,3,2};
Keypad myKeyPad = Keypad(makeKeymap(kMap), rPins, cPins, nRows, nCols);
void setup()
{
Wire.begin(I2C_ADDR);
Wire.onRequest(requestEvent);
}
void loop()
{
pKey = myKeyPad.getKey();
delay(100);
}
void requestEvent()
{
if (pKey != NO_KEY)
{
pKey = pKey;
} else {
pKey = 'X';
}
Wire.write(pKey);
}
Is there any chance to reduce maybe the library?
Libs used (Keypad.h):
#ifndef KEYPAD_H
#define KEYPAD_H
#include "utility/Key.h"
// Arduino versioning.
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#ifndef INPUT_PULLUP
#warning "Using pinMode() INPUT_PULLUP AVR emulation"
#define INPUT_PULLUP 0x2
#define pinMode(_pin, _mode) _mypinMode(_pin, _mode)
#define _mypinMode(_pin, _mode) \
do { \
if(_mode == INPUT_PULLUP) \
pinMode(_pin, INPUT); \
digitalWrite(_pin, 1); \
if(_mode != INPUT_PULLUP) \
pinMode(_pin, _mode); \
}while(0)
#endif
#define OPEN LOW
#define CLOSED HIGH
typedef char KeypadEvent;
typedef unsigned int uint;
typedef unsigned long ulong;
typedef struct {
byte rows;
byte columns;
} KeypadSize;
#define LIST_MAX 10 // Max number of keys on the active list.
#define MAPSIZE 10 // MAPSIZE is the number of rows (times 16 columns)
#define makeKeymap(x) ((char*)x)
//class Keypad : public Key, public HAL_obj {
class Keypad : public Key {
public:
Keypad(char *userKeymap, byte *row, byte *col, byte numRows, byte numCols);
virtual void pin_mode(byte pinNum, byte mode) { pinMode(pinNum, mode); }
virtual void pin_write(byte pinNum, boolean level) { digitalWrite(pinNum, level); }
virtual int pin_read(byte pinNum) { return digitalRead(pinNum); }
uint bitMap[MAPSIZE]; // 10 row x 16 column array of bits. Except Due which has 32 columns.
Key key[LIST_MAX];
unsigned long holdTimer;
char getKey();
bool getKeys();
KeyState getState();
void begin(char *userKeymap);
bool isPressed(char keyChar);
void setDebounceTime(uint);
void setHoldTime(uint);
void addEventListener(void (*listener)(char));
int findInList(char keyChar);
int findInList(int keyCode);
char waitForKey();
bool keyStateChanged();
byte numKeys();
private:
unsigned long startTime;
char *keymap;
byte *rowPins;
byte *columnPins;
KeypadSize sizeKpd;
uint debounceTime;
uint holdTime;
bool single_key;
void scanKeys();
bool updateList();
void nextKeyState(byte n, boolean button);
void transitionTo(byte n, KeyState nextState);
void (*keypadEventListener)(char);
};
#endif
and (Key.h):
#ifndef KEY_H
#define KEY_H
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define OPEN LOW
#define CLOSED HIGH
typedef unsigned int uint;
typedef enum{ IDLE, PRESSED, HOLD, RELEASED } KeyState;
const char NO_KEY = '\0';
class Key {
public:
// members
char kchar;
int kcode;
KeyState kstate;
boolean stateChanged;
Key();
Key(char userKeyChar);
void key_update(char userKeyChar, KeyState userState, boolean userStatus);
private:
};
#endif
Thank you for your effort!