Pages: [1] 2   Go Down
Author Topic: 8/8 button matrix  (Read 1160 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,
Can you help with the following code?
I have a 8/8 button matrix connected  to a button shield,
which is connected to an Arduino Mega.
I am trying to insert characters on a computer display.
It's my first code and I am a bit struggling.
Can you help?
Any suggestion would be useful.
Regards



Code:
// 8/8 keypad to print characters
// on computer display
#include <Keypad.h>

int R0=9;
int R1=8;
int R2=7;
int R3=6;
int R4=5;
int R5=4;
int R6=3;
int R7=2;
void setup();
{
pinMode(R0, INPUT);
pinMode(R1, INPUT);
pinMode(R2, INPUT);
pinMode(R3, INPUT);
pinMode(R4, INPUT);
pinMode(R5, INPUT);
pinMode(R6, INPUT);
pinMode(R7, INPUT);
}

const byte Rows = 8; // 8 rows
const byte Cols = 8; // 8 columns
char keys [Rows] [Cols] ={
 
  {'a','b','c','d','e','f','g','h'},
  {'i','j','k','l','m','n','o','p'},
  {'q','r','s','t','u','v','w','x'},
  {'y','z','A','B','C','D','E','F'},
  {'G','H','I','J','K','L','M','N'},
  {'O','P','Q','R','S','T','U','V'},
  {'W','X','Y','Z','1','2','3','4'},
  {'5','6','7','8','9','0','.',','},
};

  byte rowPins [Rows] = {R0, R1, R2, R3, R4, R5, R6, R7};
  // connect to row pinouts of the keypad
  byte colPins [Cols] = {A0, A1, A2, A3, A4, A5, A6, A7};
  // connect to column pinouts of keypad
 
  Keypad keypad = Keypad( makeKeymap (keys), rowPins, colPins,
  Rows, Cols };
 
  void setup() {
    Serial.begin (9600);
    Keypad.begin();
  }
 
  void loop() {
    char key = keypad.getKey();
   
    if (key != No_Key){
      Serial.println( key );
    }
  } 
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 108
Posts: 3783
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok what is it doing or not doing? Any errors?

Edit: Keypad.begin() seems odd to me, none of the other keypad codes I've helped write had that in them.
« Last Edit: February 12, 2013, 03:32:04 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Queens, New York
Offline Offline
Faraday Member
**
Karma: 108
Posts: 3783
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No cross posting please!
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Those are the errors:
14:error: expected unqualified-id before '{' token
44:error: 'Keypad' does not name a type
In function 'void setup()':
50: error: 'Keypad was not declared in this scope
In function 'void loop()':
54: error: 'keypad' was not declared in this scope
56: error: 'No_Key' was not declared in this scope

Thanks
Logged

Global Moderator
Melbourne, Australia
Online Online
Brattain Member
*****
Karma: 511
Posts: 19317
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

- Moderator
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok what is it doing or not doing? Any errors?

Edit: Keypad.begin() seems odd to me, none of the other keypad codes I've helped write had that in them.

I tried but I have the same errors
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4398
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void setup();
Lose the semi colon

Have you got the Keypad.h file and, if so, which folder is it in ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Queens, New York
Offline Offline
Faraday Member
**
Karma: 108
Posts: 3783
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why do you have two setup() functions?

Code:
void setup();
{
pinMode(R0, INPUT);
pinMode(R1, INPUT);
pinMode(R2, INPUT);
pinMode(R3, INPUT);
pinMode(R4, INPUT);
pinMode(R5, INPUT);
pinMode(R6, INPUT);
pinMode(R7, INPUT);
}

And...

Code:
void setup() {
    Serial.begin (9600);
    Keypad.begin();
  }
« Last Edit: February 12, 2013, 03:54:44 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27418
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You have void setup twice:
Code:
int R7=2;
void setup();
{
pinMode(R0, INPUT);
pinMode(R1, INPUT);
and
Code:
 Keypad keypad = Keypad( makeKeymap (keys), rowPins, colPins,
  Rows, Cols };
  
  void setup() {
    Serial.begin (9600);
    Keypad.begin();
  }
Probably move the stuff in the 2nd one to the end of the first one.
keypad.begin also does not belong:
http://playground.arduino.cc/code/Keypad
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 652
Posts: 50869
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void setup();
Why is there a semicolon after this function declaration?

Code:
  Keypad keypad = Keypad( makeKeymap (keys), rowPins, colPins,
  Rows, Cols };
That's a curly brace on the end, not a parenthesis.

Code:
    Keypad.begin();
You call methods using an instance (keypad) not a class name (Keypad). The begin method takes an argument - the keymap that makeKeymap() creates. But, since you have already supplied that to the instance, there is no reason to call keymap.begin() again.

You have two setup() functions.

Code:
    if (key != No_Key){
The constant is NO_KEY.

After correcting all these errors, the code compiles.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why do you have two setup() functions?
I don't know.
I tried to write this code using different examples.
There is not a proper code on the internet for this 8/8 matrix.
I used a normal Arduino header and I don't know about the folder inside.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
This is my new code.
I still got errors.
Now what is wrong?

Regards


[code// 8/8 keypad to print characters
// on computer display
#include <Keypad.h>

int R0=9;
int R1=8;
int R2=7;
int R3=6;
int R4=5;
int R5=4;
int R6=3;
int R7=2;

void setup()
{
pinMode(R0, INPUT);
pinMode(R1, INPUT);
pinMode(R2, INPUT);
pinMode(R3, INPUT);
pinMode(R4, INPUT);
pinMode(R5, INPUT);
pinMode(R6, INPUT);
pinMode(R7, INPUT);


const byte Rows = 8; // 8 rows
const byte Cols = 8; // 8 columns
char keys [Rows] [Cols] ={
  
  {'a','b','c','d','e','f','g','h'},
  {'i','j','k','l','m','n','o','p'},
  {'q','r','s','t','u','v','w','x'},
  {'y','z','A','B','C','D','E','F'},
  {'G','H','I','J','K','L','M','N'},
  {'O','P','Q','R','S','T','U','V'},
  {'W','X','Y','Z','1','2','3','4'},
  {'5','6','7','8','9','0','.',','},
};

  byte rowPins [Rows] = {R0, R1, R2, R3, R4, R5, R6, R7};
  // connect to row pinouts of the keypad
  byte colPins [Cols] = {A0, A1, A2, A3, A4, A5, A6, A7};
  // connect to column pinouts of keypad
  
  Keypad keypad = Keypad( makeKeymap (keys), rowPins, colPins,
  Rows, Cols );
  
  
    Serial.begin (9600);
  
  void loop() {
    char key = keypad.getKey();
    
    if (key != No_Key){
      Serial.println( key );
    }
  }
  
« Last Edit: February 12, 2013, 04:28:09 pm by littlewolf » Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 27418
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think this stuff all goes before void setup
Code:
const byte Rows = 8; // 8 rows
const byte Cols = 8; // 8 columns
char keys [Rows] [Cols] ={
 
  {'a','b','c','d','e','f','g','h'},
  {'i','j','k','l','m','n','o','p'},
  {'q','r','s','t','u','v','w','x'},
  {'y','z','A','B','C','D','E','F'},
  {'G','H','I','J','K','L','M','N'},
  {'O','P','Q','R','S','T','U','V'},
  {'W','X','Y','Z','1','2','3','4'},
  {'5','6','7','8','9','0','.',','},
};

  byte rowPins [Rows] = {R0, R1, R2, R3, R4, R5, R6, R7};
  // connect to row pinouts of the keypad
  byte colPins [Cols] = {A0, A1, A2, A3, A4, A5, A6, A7};
  // connect to column pinouts of keypad
 
  Keypad keypad = Keypad( makeKeymap (keys), rowPins, colPins,
  Rows, Cols );
You're missing the } to end void setup

May not need these, I think the keypad callout takes care of all this
Code:
pinMode(R0, INPUT);
pinMode(R1, INPUT);
pinMode(R2, INPUT);
pinMode(R3, INPUT);
pinMode(R4, INPUT);
pinMode(R5, INPUT);
pinMode(R6, INPUT);
pinMode(R7, INPUT);
Check the sample code at the end of the link I posted before to the keypad library in the playground.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 652
Posts: 50869
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
This is my new code.
I still got errors.
Now what is wrong?
What are they?

You REALLY need to learn what should be global (outside any function) and what should be in a function. There is an example that comes with the Keypad library. Modifying that example to use 8 rows and 8 columns is trivial. If you pay attention.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 54
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I modified everything and I also included the
keypad library into the Arduino.
The error I receive now is to declare keypad into
void loop function
I think it's almost done
Just the last few bits
Thanks


Code:
// 8/8 keypad to print characters
// on computer display

#include <Keypad.h>

int R0=9;
int R1=8;
int R2=7;
int R3=6;
int R4=5;
int R5=4;
int R6=3;
int R7=2;

const byte Rows = 8; // 8 rows
const byte Cols = 8; // 8 columns
char keys [Rows] [Cols] ={
 
  {'a','b','c','d','e','f','g','h'},
  {'i','j','k','l','m','n','o','p'},
  {'q','r','s','t','u','v','w','x'},
  {'y','z','A','B','C','D','E','F'},
  {'G','H','I','J','K','L','M','N'},
  {'O','P','Q','R','S','T','U','V'},
  {'W','X','Y','Z','1','2','3','4'},
  {'5','6','7','8','9','0','.',','},
};

  byte rowPins [Rows] = {R0, R1, R2, R3, R4, R5, R6, R7};
  // connect to row pinouts of the keypad
  byte colPins [Cols] = {A0, A1, A2, A3, A4, A5, A6, A7};
  // connect to column pinouts of keypad
 
  Keypad customKeypad = Keypad( makeKeymap (keys), rowPins, colPins,
  Rows, Cols );
 
  void setup()
  {
    Serial.begin (9600);
  }
  void loop() {
    char key = keypad.getKey();
   
    if (key != No_Key){
      Serial.println( key );
    }
  }
Logged

Pages: [1] 2   Go Up
Jump to: