Go Down

Topic: 8/8 button matrix (Read 1 time) previous topic - next topic

littlewolf

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: [Select]
// 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 );
    }
  } 

HazardsMind

#1
Feb 12, 2013, 09:24 pm Last Edit: Feb 12, 2013, 09:32 pm by HazardsMind Reason: 1
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.
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

HazardsMind

My GitHub:
https://github.com/AndrewMascolo?tab=repositories

littlewolf

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

Nick Gammon

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

Threads merged.

- Moderator
Please post technical questions on the forum, not by personal message. Thanks!

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

littlewolf


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

UKHeliBob

Code: [Select]
void setup();Lose the semi colon

Have you got the Keypad.h file and, if so, which folder is it in ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

HazardsMind

#7
Feb 12, 2013, 09:51 pm Last Edit: Feb 12, 2013, 09:54 pm by HazardsMind Reason: 1
Why do you have two setup() functions?

Code: [Select]
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: [Select]
void setup() {
    Serial.begin (9600);
    Keypad.begin();
  }
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

CrossRoads

You have void setup twice:
Code: [Select]

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

and
Code: [Select]

 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
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

PaulS

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

Code: [Select]
  Keypad keypad = Keypad( makeKeymap (keys), rowPins, colPins,
  Rows, Cols };

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

Code: [Select]
    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: [Select]
    if (key != No_Key){
The constant is NO_KEY.

After correcting all these errors, the code compiles.

littlewolf


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.

littlewolf

#11
Feb 12, 2013, 10:22 pm Last Edit: Feb 12, 2013, 10:28 pm by littlewolf Reason: 1
Code: [Select]
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 );
   }
 }
 

CrossRoads

I think this stuff all goes before void setup
Code: [Select]

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: [Select]

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

PaulS

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.

littlewolf

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: [Select]
// 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 );
    }
  }

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy