Pages: [1]   Go Down
Author Topic: Using COM-08653 (12 Button Keypad) as simple buttons on microcontroller  (Read 2386 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The microcontroller I'm using is the Ethernet Pro Microcontroller (similar to Arduino Uno)

I have this 12 button keypad on the way. The picture below is which buttons are assigned to which key..



My questions are....

1. Are 10 kohm resistors needed to be connected between EACH of the connections to the powersupply?

2. Can this "button" tutorial (http://www.arduino.cc/en/Tutorial/Button) apply with this keypad?

3. After stating each of the 7 pins as INPUT's, will I have a problem pressing multiple buttons at the same time since certain buttons account for the same pin? (ex. "1", "2", "3" share pin 2)
If so, can using the Boolean argument && designation specific buttons?
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I seem to recall a suggested amendment to the keypad library to allow for multiple button presses. Can't remember offhand where it was, but somewhere in the forum.

See:

http://arduino.cc/playground/Code/Keypad

http://arduino.cc/playground/Main/KeypadTutorial

Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here:

http://arduino.cc/forum/index.php?topic=95027.0
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks.

I also saw someone suggesting to simply set the pins as inputs and just use the key pad similar to the "button" tutorial.

http://forum.bildr.org/viewtopic.php?t=388

Code:
    void setup(void)
    {

      pinMode(12, INPUT);
      digitalWrite(12, HIGH);

    }

    void loop(void)
    {

      if (digitalRead(12) == LOW)
      {
        // Do something
      }

      else
      {
        // well then do something else
      }
    }


Is this something I cannot do with this keypad?
In short, I want to use this and input commands to my microcontroller.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You have a matrix. Use the matrix library. The keypad one. If you make them inputs you won't read anything. A column has to be output and a row input. Then it pulses each column and tests each row. That's how the matrix works.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay. Read through the examples and thought up of a situation I may run into. In my loop, after I defined my keys (as shown in the tutorial), if I decided to consider using "if" statements, and my approach is to say "if, at a point in time, I press and hold '4' on the keypad, then the if statement will follow through in my loop"

for example:

Code:
void loop()
{

char key = kpd.getKey();
    if(key == ‘4’)
  {   
      // My specific command
  }

^^
Would this theoretically work until I release the '4' key?
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7197
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

It should work.
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I would probably make whatever happens on the key into a function, and inside that do whatever until you detect it is no longer pressed. Say for example you turn on a light, just doing that multiple times won't turn the light off. So more like:

Code:
void button4pressed ()
  {
 
  // turn light on

  while (kpd.getKey() == '4')
    {}   // wait for release

  // turn light off

  }  // end of button4pressed
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, that explained a LOT.

Also, to save some pins on my microcontroller, is it possible to choose which part of the matrix keyboard I want functional ONLY?

for example, if I only wanted ['1' , '2' ; '4' , '5'] for a 2x2, can I just create the keyboard as a 2x2 matrix in my sketch and leave the rest nonfunctional?
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7197
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you, that explained a LOT.

Also, to save some pins on my microcontroller, is it possible to choose which part of the matrix keyboard I want functional ONLY?

for example, if I only wanted ['1' , '2' ; '4' , '5'] for a 2x2, can I just create the keyboard as a 2x2 matrix in my sketch and leave the rest nonfunctional?

Why would you need that? You don't have to use a matrix keypad. One pin for one key you use 4 keys, or two column by two row you also use 4 pins.
Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Liudr is right. You could conceivably do what you said, but you need 2 rows and 2 columns, so that is 4 inputs. You may as well just hook up 4 buttons.

But yes, you could connect up the first two columns and the first two rows and save 3 pins compared to what you are doing now.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I opted to just using the whole keypad.

Also, I used your suggestion to create a function to control the commands for when I press a specific button on the keypad. I haven't been able to test it out yet today since I'm currently out of town. The sketch compiled; but, my question is:

According to my current sketch, is the logic correct in terms of what I want it to do?
In other words, I want it so when I press '*' on the key pad, the servo will run as long as I hold it.

Code:
#include <Servo.h>
#include <Keypad.h>
#include <BMSerial.h>
#include <RoboClaw.h>

#define address 0x80


// Keypad Stuff

const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = { 3, 4, 5, 6 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 0, 1, 2 };
// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );




// Joypad Buttons
const int upA = 7;
const int downA = 8;
const int upB = 12;
const int downB = 13;

// Servo stuff
Servo myservo;  // Create servo object to control servo
int pos = 90; // Variable to store the servo position

// RoboClaw stuff
RoboClaw roboclaw(5,6);
int mSpeed = 64;



// HSR-1425CR controls
void buttonstarpressed ()
  {
  while (kpd.getKey() == '*')
    {
      for(pos; pos < 180; pos += 1) // Begin to rotate pressure washer from rest to full power
        {
         myservo.write(pos);

         // Delay increase in “angle” by 10 ms before going through loop again
         delay(10);
        }
    }   // wait for release
  myservo.write(90);
  }
 
void buttonpoundpressed ()
  {   
  while (kpd.getKey() == '#')
    {
      for(pos; pos > 0; pos -= 1) // Begin to rotate pressure washer from rest to full power
         {
          myservo.write(pos);

          // Delay increase in “angle” by 10 ms before going through loop again
          delay(10);
         }
    }
  myservo.write(90);
  }

void setup()
{

 
  pinMode(upA, INPUT);
  pinMode(downA, INPUT);
  pinMode(upB, INPUT);
  pinMode(downB, INPUT);
 
 
  myservo.attach(11);  // “Attaches” HSR1425CR servo on pin 11
  myservo.write(pos);  // Initially set servo motor to zero movement (“90 degrees”)
                    // Full power in direction 1: “0 degrees”
                    // Full power in direction 2: “180 degrees”

  Serial.begin(2400);
}

void loop()
{
  char key = kpd.getKey();
 

  // RoboClaw control

    if(digitalRead(upA) == LOW)
  {   
    roboclaw.ForwardM1(address, mSpeed);
  }

    if(digitalRead(downA) == LOW)
  {   
    roboclaw.BackwardM1(address, mSpeed); 
  }
 
    if(digitalRead(upB) == LOW)
  {   
    roboclaw.ForwardM2(address, mSpeed); 
  }

    if(digitalRead(downB) == LOW)
  {   
    roboclaw.BackwardM2(address, mSpeed); 
  }

}
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18778
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
According to my current sketch, is the logic correct in terms of what I want it to do?

Well, no, because I don't see where buttonstarpressed is called.


Code:
void loop()
{
  char key = kpd.getKey();

...

}

You don't use "key" there so why find out what it is?

I would expect you to test (eg. switch on) the value of key and call the appropriate function.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 19
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
According to my current sketch, is the logic correct in terms of what I want it to do?

Well, no, because I don't see where buttonstarpressed is called.


Code:
void loop()
{
  char key = kpd.getKey();

...

}

You don't use "key" there so why find out what it is?

I would expect you to test (eg. switch on) the value of key and call the appropriate function.

I see...

Code:
void loop() {

buttonpoundpressed ();

...

}

buttonpoundpressed () {

while(kpd.getKey() == '#'){
// command to run until this is no longer valid

for(pos; pos < 180; pos += 1) // Begin to rotate pressure washer from rest to full power
        {
         myservo.write(pos);
         delay(10);

}

...
}
Logged

Pages: [1]   Go Up
Jump to: