Go Down

Topic: How do I declare a new class definition (Read 1 time) previous topic - next topic


How do I declare the following so that the new class can be seen by other modules.
Code: [Select]

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
byte rowPins[ROWS] = {2,3,4,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

All of the above is declared in a header for the main module but I need to be able to call the keypad like this
Code: [Select]
and like this
Code: [Select]
whichkey = keypad.getKey();
from other modules. I get this error compiling with a CMake make file :-  undefined reference to `Keypad::Keypad(char*, unsigned char*, unsigned char*, unsigned char, unsigned char, unsigned char)'.
There are many more like this all referring to class definitions.
How to do please?

Rather people think you to be a fool than you open your mouth and confirm it.


May 30, 2011, 12:04 am Last Edit: May 30, 2011, 12:07 am by PaulS Reason: 1
I get this error compiling with a CMake make file

When compiling what with a CMake make file?

Do you get the same error when compiling with the Arduino IDE?

If the code shown in the top window is placed inside a class, you will need to refer to the members of that class (keypad, etc.) using an instance of that class. key = keypad.getKey(); will not work, because keypad is a member variable.

Terry King


Take a look at:

Which is Alexander's tutorial on Libraries.... Well done!
Regards, Terry King  ..On the Red Sea at KAUST.edu.sa
terry@yourduino.com  LEARN! DO! (Arduino Boards, Sensors, Parts @ http://yourduino.com

Go Up