Go Down

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

Marius

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] = {
  {'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: [Select]
keypad.addEventListener(keypadEvent);
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.

PaulS

#1
May 30, 2011, 12:04 am Last Edit: May 30, 2011, 12:07 am by PaulS Reason: 1
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.

Terry King

Hi,

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

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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy