8/8 button matrix

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

// 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 );
    }
  }

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.

No cross posting please!

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

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

Threads merged.

  • Moderator

HazardsMind:
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

void setup();Lose the semi colon

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

Why do you have two setup() functions?

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

 void setup() {
    Serial.begin (9600);
    Keypad.begin();
  }

You have void setup twice:

int R7=2;
void setup();
{
pinMode(R0, INPUT);
pinMode(R1, INPUT);

and

  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

void setup();

Why is there a semicolon after this function declaration?

  Keypad keypad = Keypad( makeKeymap (keys), rowPins, colPins,
  Rows, Cols };

That's a curly brace on the end, not a parenthesis.

    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.

    if (key != No_Key){

The constant is NO_KEY.

After correcting all these errors, the code compiles.

HazardsMind:
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.

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 );
    }
  }

I think this stuff all goes before void setup

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

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.

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.

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

// 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 );
    }
  }

Refer to reply #9, your answer is at the bottom.

littlewolf:
The error I receive now is to declare keypad into

Copy the errors, paste them here.

"is to declare keypad into" doesn't make sense.

The errors I get:
schetch_feb07a.ino: In function 'void loop()':
42: error: 'keypad was not declared in this scope
44: error: 'No_Key' was not declared in this scope

Just a few errors compared to the errors I got before.
Many thanks

You have declared and instance of Keypad and called it customKeypad

  Keypad customKeypad = Keypad( makeKeymap (keys), rowPins, colPins,
  Rows, Cols );

Later on you refer to it as keypad

   char key = keypad.getKey();

Change the second one to

   char key = customKeypad.getKey();

44: error: 'No_Key' was not declared in this scope

And it wasn't in the example I told you to look at, either. I've already told you what to do about this. Start listening.