brelliott18

keypad interfacing

8 posts in this topic

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

Share this post


Link to post
Share on other sites

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

You didn't "search" very hard.

 

;)

Share this post


Link to post
Share on other sites

You didn't "search" very hard.

 

;)

 

You didn't "search" very hard.

 

;)

So where is this information for the Msp430G2553  [ NOT the Arduino - Those didn't work ]  ?

Share this post


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

Share this post


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.)

Share this post


Link to post
Share on other sites

Solved - thanks for help anyway. Thought I could use P1_1 and P1_2  but couldn't  - used P1_3 upwards then P2 instead - works fine !

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now