Forum >Matrix Keypad problem
General

Matrix Keypad problem

userHead Karltjuh92 2012-01-05 13:29:47 5724 Views4 Replies
Hey all,

I am new these embedded systems. I really like it. I only got one problem, some days ago I recieved my Matrix keybad FIT0129 ([url=http://www.dfrobot.com/index.php?route=product/product&filter_name=FIT0129&product_id=450]http://www.dfrobot.com/index.php?route=product/product&filter_name=FIT0129&product_id=450[/url])

I dont know how to use it really so I made this: ( written in c with the arduino IDE)

char cycle(){
delay(50);
digitalWrite(8,HIGH);
if(digitalRead(7)==HIGH){
return '0';
} else if (digitalRead(6)==HIGH){
return '#';
}else if (digitalRead(5)==HIGH){
return '*';
}else if (digitalRead(4)==HIGH){
return 'D';
}
digitalWrite(8,LOW);

delay(50);
digitalWrite(9,HIGH);

if(digitalRead(7)==HIGH){
return '8';
} else if (digitalRead(6)==HIGH){
return '9';
}else if (digitalRead(5)==HIGH){
return '7';
}else if (digitalRead(4)==HIGH){
return 'C';
}
digitalWrite(9,LOW);

delay(50);
digitalWrite(10,HIGH);

if(digitalRead(7)==HIGH){
return '5';
} else if (digitalRead(6)==HIGH){
return '6';
}else if (digitalRead(5)==HIGH){
return '4';
}else if (digitalRead(4)==HIGH){
return 'B';
}
digitalWrite(10,LOW);

delay(50);
digitalWrite(11,HIGH);

if(digitalRead(7)==HIGH){
return '2';
} else if (digitalRead(6)==HIGH){
return '3';
}else if (digitalRead(5)==HIGH){
return '1';
}else if (digitalRead(4)==HIGH){
return 'A';
}
digitalWrite(11,LOW);
}

In this part of the code i want to return the input char. (that works well i guess)

in this part I want to change a case with it but it doesnt work well
if(cycle()=='1'){
inputCase = 1;


Does someone know what is the problem?

Greets
Karl
2012-01-07 04:23:17 Oh Thanks for the unlock, I can reply finally. Thank you for your help! I'm still new at the forum it worked good! Thanks! userHeadPic Karltjuh92
2012-01-06 18:22:45 Not sure why this topic was locked. Unlocked again. userHeadPic Hector
2012-01-05 18:25:52 I also found this post which teaches you how to use only 3 wires. I think its pretty cool and worth a try


[url=http://www.instructables.com/id/Arduino-3-wire-Matrix-Keypad/]http://www.instructables.com/id/Arduino-3-wire-Matrix-Keypad/[/url]

userHeadPic Hector
2012-01-05 18:18:22 Hi Karl,


I found this sample code on the net. You might need to change the pins either in the program or physically to match each other.


[code]
/*  Keypadtest.pde
*
*  Demonstrate the simplest use of the  keypad library.
*
*  The first step is to connect your keypad to the
*  Arduino  using the pin numbers listed below in
*  rowPins[] and colPins[]. If you want to use different
*  pins then  you  can  change  the  numbers below to
*  match your setup.
*
*/
#include <Keypad.h>

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] = { 9, 8, 7, 6 };
// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = { 12, 11, 10 };

// Create the Keypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

#define ledpin 13

void setup()
{
  digitalWrite(ledpin, HIGH);
  Serial.begin(9600);
}

void loop()
{
  char key = kpd.getKey();
  if(key)  // Check for a valid key.
  {
    switch (key)
    {
      case '*':
        digitalWrite(ledpin, LOW);
        break;
      case '#':
        digitalWrite(ledpin, HIGH);
        break;
      default:
        Serial.println(key);
    }
  }
}
[/code]
userHeadPic Hector