Pages: [1]   Go Down
Author Topic: How do I declare a new class definition  (Read 1117 times)
0 Members and 1 Guest are viewing this topic.
Centurion RSA
Offline Offline
Full Member
***
Karma: 0
Posts: 166
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How do I declare the following so that the new class can be seen by other modules.
Code:
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'#','0','*','D'}
};
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:
keypad.addEventListener(keypadEvent);
and like this
Code:
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?
 

 

Logged

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.
« Last Edit: May 29, 2011, 05:07:09 pm by PaulS » Logged

Red Sea, Saudi Arabia
Offline Offline
God Member
*****
Karma: 12
Posts: 579
..On The Red Sea
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Take a look at:
http://www.arduino.cc/playground/Code/Library

Which is Alexander's tutorial on Libraries.... Well done!
Logged

Regards, Terry King  ..On the Red Sea at KAUST.edu.sa
terry@yourduino.com  LEARN! DO! (Arduino Boards, Sensors, Parts @ http://yourduino.com

Pages: [1]   Go Up
Jump to: