Jump to content
43oh

keypad interfacing


Recommended Posts

I have recently bought a LaunchPad 2553. I am a comparitive novice.

 

I am trying to add a  4 X 4 matrix keypad.  I copied some code from an Arduino source and changed #Arduino references to #Energia. I commented out a  #WProgram statement - what is this ?

 

The code compiled and verified OK .  I connected the 8 wires from keypad  to p1.0 -p1.7 [ and tried other ports as well ].

 

The output was sent to the Serial monitor via Serial.println( key ).  I could only get any output by pressing many keys at the same time.

 

I looked at the keyboard.h  file but it went nothing to me.  How do the DigitalReads get initiated ?

 

 [ Serial.println ("hello world " ) worked so the program does get to the right place  ]

 

Any suggestions please  - pointers to existing code snippets - I can't fine any . Thanks

Link to post
Share on other sites

This is part of the Arduino code I found for keypads [ keyboard.h ].  How should ths be altered [ if necessary ] to run on the MSP430G2553 ?

 

Assuming I use p1.0 to p1.7  ??? for the 8 wires coming from the keypad [ 4 X 4 ]

 

#define INPUT_PULLUP  0x2   - does this need changing ?

 

 

 

 

#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

Link to post
Share on other sites

Don't see anything obviously wrong with the INPUT_PULLUP section (since Energia defines INPUT_PULLUP the code here isn't used).

 

Would help if you post the rest of the code (as you have modified it), or post a link to the library you are modifying (if you haven't changed it).  (Please use the code attribute - the <> icon - when posting code.)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...