ADDIKIT Keypad Question and Error messages

I have a tone dialer project that a started using code from here. I am currently using the exact code, with the exception of the the phone number, that is on the website. I decided that I wanted to make a live push button dialer using the key pad shown in the picture.
My first problem is, I don’t know how the keypad is wired. My second problem is, if I were to use similar code to my reconfiguration below would my project work if I were to take into account how to use the keypad.

/* DTMF encoder (Dual Tone Generator) for a Phone Dialer
 *  Created by David Dubins, May 13th, 2016.
 *  Released into the public domain.
 * 
 * SETUP: 
 * - Connect Pins 12 and 13 to the + speaker terminal, each through their own 240 Ohm resistor
 * - Connect a 4.7 uF capacitor between the + and - terminals of the speaker
 * - Connect speaker GND to Arduino GND
 * - Connect a momentary switch to Pin 8, and the other side of the switch to GND
 */

const byte tone1Pin=12; // pin for tone 1
const byte tone2Pin=13; // pin for tone 2
byte PhoneNumber[]={0}; // for special characters: 10=*, 11=#, 12=1sec delay
byte PhoneNumberLength = 1;  // adjust to length of phone number
byte PhoneNumber1[]={1}; // for special characters: 10=*, 11=#, 12=1sec delay
byte PhoneNumberLength1 = 1;  // adjust to length of phone number
const byte buttonPin=11; // for momentary switch
const byte buttonPin0=0; // dial 0
const byte buttonPin1=1; // dial 1 

// frequencies adopted from: https://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling
int DTMF[13][2]={
  {941,1336}, // frequencies for touch tone 0
  {697,1209}, // frequencies for touch tone 1
  {697,1336}, // frequencies for touch tone 2
  {697,1477}, // frequencies for touch tone 3
  {770,1209}, // frequencies for touch tone 4
  {770,1336}, // frequencies for touch tone 5
  {770,1477}, // frequencies for touch tone 6
  {852,1209}, // frequencies for touch tone 7
  {852,1336}, // frequencies for touch tone 8
  {852,1477}, // frequencies for touch tone 9
  {941,1209}, // frequencies for touch tone *
  {941,1477}, // frequencies for touch tone #
  {0,0} // pause
};

void setup()
{  
  pinMode(tone1Pin,OUTPUT); // Output for Tone 1
  pinMode(tone2Pin,OUTPUT); // Output for Tone 2
  pinMode(buttonPin,INPUT_PULLUP); // Button
  pinMode(buttonPin0,INPUT_PULLUP); // Button 0
  pinMode(buttonPin1,INPUT_PULLUP); // Button 1
}

void loop()
{
  if(digitalRead(buttonPin0)==LOW){  // If the button is pushed
      dialNumber(PhoneNumber,PhoneNumberLength);  // Dial the number 0
 
  if(digitalRead(buttonPin0)==LOW){  // If the button is pushed
      dialNumber(PhoneNumber1,PhoneNumberLength1);  // Dial the number 1
  }
}


void playDTMF(byte digit, byte duration){
  boolean tone1state=false;
  boolean tone2state=false;
  int tone1delay=(500000/DTMF[digit][0])-10; // calculate delay (in microseconds) for tone 1 (half of the period of one cycle). 10 is a fudge factor to raise the frequency due to sluggish timing.
  int tone2delay=(500000/DTMF[digit][1])-10; // calculate delay (in microseconds) for tone 2 (half of the period of one cycle). 10 is a fudge factor to raise the frequency due to sluggish timing.
  unsigned long tone1timer=micros();
  unsigned long tone2timer=micros();
  unsigned long timer=millis(); // for timing duration of a single tone
  if(digit==12){
    delay(1000); // one second delay if digit is 12
  } else {
    while(millis()-timer<duration){
      if(micros()-tone1timer>tone1delay){
        tone1timer=micros(); // reset the timer
        tone1state=!tone1state; // toggle tone1state
        digitalWrite(tone1Pin, tone1state);
      }
      if(micros()-tone2timer>tone2delay){
        tone2timer=micros(); // reset the timer
        tone2state=!tone2state; // toggle tone2state
        digitalWrite(tone2Pin, tone2state);
      }
    }
    digitalWrite(tone1Pin,LOW);
    digitalWrite(tone2Pin,LOW);
  }
}

void dialNumber(byte number[],byte len){
  for(int i=0;i<len;i++){
    playDTMF(number[i], 100);  // 100 msec duration of tone
    delay(100); // 100 msec pause between tones
  }
}
//END OF FILE

Also, what is wrong with the modified code? I have this error on the code above:
Arduino: 1.6.5 (Windows 8.1), Board: “Arduino Leonardo”

C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_LEONARDO -DARDUINO_ARCH_AVR -DUSB_VID=0x2341 -DUSB_PID=0x8036 -DUSB_MANUFACTURER=“Unknown” -DUSB_PRODUCT=“Arduino Leonardo” -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\leonardo C:\Users\Owner\AppData\Local\Temp\build5327851873028243020.tmp\DMTF1.cpp -o C:\Users\Owner\AppData\Local\Temp\build5327851873028243020.tmp\DMTF1.cpp.o

DMTF1.ino: In function ‘void loop()’:
DMTF1.ino:59:41: error: a function-definition is not allowed here before ‘{’ token
DMTF1.ino:92:1: error: expected ‘}’ at end of input
a function-definition is not allowed here before ‘{’ token
Thanks Every One!

in the code:

void loop()
{
  if(digitalRead(buttonPin0)==LOW){  // If the button is pushed
      dialNumber(PhoneNumber,PhoneNumberLength);  // Dial the number 0
 
  if(digitalRead(buttonPin0)==LOW){  // If the button is pushed
      dialNumber(PhoneNumber1,PhoneNumberLength1);  // Dial the number 1
  }
}

missing a closing } in the first if statement, so the loop isnt closed by the time you define the function below it.

The keypad has 7 wires, one for each of the 4 rows and 3 colums. Hitting each button will short a different pair of wires together. There's a tutorial here

Should be pretty easy to incorporate. I had to do something similar in the intro microcontrollers class way back in college.

My first problem is, I don't know how the keypad is wired.

Get a multi-meter, and learn. Pressing any key will connect two of the 7 pins.

Number the pins 1 to 7. Create a table, 3 x 4. In each cell, identify the two pins that are connected when the corresponding button is pressed.

Soon, you'll see a pattern between the row and column values, and you'll know which pins are row pins and which are column pins.

As for the errors, count the number of curly braces in loop. The number of open curly braces does not match the number of close curly braces. The first if statement is missing a close curly brace.

Why do you want to dial the same two one digit phone number when one button is pressed?

PaulS:
Why do you want to dial the same two one digit phone number when one button is pressed?

I don't quite understand the question, but I think the answer is that I don't want to.

bDeters:
The keypad has 7 wires, one for each of the 4 rows and 3 colums. Hitting each button will short a different pair of wires together.

I figured it had something to do with that, thanks.

I'm not quite understanding how to set up an "if" statement with the tutorial code to dial a specific number.

#include "Arduino.h"
#include "Keypad.h"

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

As per the example code with that library, you poll the keypad periodically with getKey().

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

  if (key != NO_KEY){
    //do something
  }
}

bDeters:
As per the example code with that library, you poll the keypad periodically with getKey().

void loop(){

char key = keypad.getKey();

if (key != NO_KEY){
   //do something
 }
}

Yeah, but do I try this

void loop(){
  char key = keypad.getKey();
   if(key !=4,2){  // If the button is pushed
      dialNumber(PhoneNumber,PhoneNumberLength);  // Dial the number 0
  
}

because it is not really working. All it does is it dials the tone for 0 constantly and I tried putting in an ==HIGH or ==LOW but it doesn't work.

I think you misunderstand what datatype "key" is, and what the comma does. First lets see what this actually does:

if(key !=4,2)

So in this case, the comma separates this into two statements, but the way the comma works here, only the second statement gets returned to the "if" (hint, 2 != FALSE). If you wanted to compare a value to two different values you usually compare both separately

Second, understand that the variable key is either a character from your matrix:

char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}

Or key == NO_KEY. So you want to compare it to a char like '4' or '2', not an integer like 4 or 2.

You can use a switch statement to easily do different things depending on which button is pressed. This example does just that

bDeters:
I think you misunderstand what datatype “key” is, and what the comma does. First lets see what this actually does:

if(key !=4,2)

So in this case, the comma separates this into two statements, but the way the comma works here, only the second statement gets returned to the “if” (hint, 2 != FALSE). If you wanted to compare a value to two different values you usually compare both separately

Second, understand that the variable key is either a character from your matrix:

char keys[ROWS][COLS] = {

{‘1’,‘2’,‘3’},
  {‘4’,‘5’,‘6’},
  {‘7’,‘8’,‘9’},
  {’*’,‘0’,’#’}



Or key == NO_KEY. So you want to compare it to a char like '4' or '2', not an integer like 4 or 2.

You can use a [switch](https://www.arduino.cc/en/Reference/SwitchCase) statement to easily do different things depending on which button is pressed. [This](https://playground.arduino.cc/KeypadTutorial/EventKeypad) example does just that

Really, I do not understand at all. I am in no way a programmer, so please help a little more and define terms, thanks.

bDeters:
I think you misunderstand what datatype “key” is, and what the comma does. First lets see what this actually does:

if(key !=4,2)

So in this case, the comma separates this into two statements, but the way the comma works here, only the second statement gets returned to the “if” (hint, 2 != FALSE). If you wanted to compare a value to two different values you usually compare both separately

Second, understand that the variable key is either a character from your matrix:

char keys[ROWS][COLS] = {

{‘1’,‘2’,‘3’},
 {‘4’,‘5’,‘6’},
 {‘7’,‘8’,‘9’},
 {’*’,‘0’,’#’}



Or key == NO_KEY. So you want to compare it to a char like '4' or '2', not an integer like 4 or 2.

You can use a [switch](https://www.arduino.cc/en/Reference/SwitchCase) statement to easily do different things depending on which button is pressed. [This](https://playground.arduino.cc/KeypadTutorial/EventKeypad) example does just that

I figured out that this code will let me press a button and it will play the zero tone, but it will play the zero tone on any button. How do I set it up for each individual tone according to the button.

#include <Keypad.h>

 /* DTMF encoder (Dual Tone Generator) for a Phone Dialer
 *  Created by David Dubins, May 13th, 2016.
 *  Released into the public domain.
 * 
 * SETUP: 
 * - Connect Pins 12 and 13 to the + speaker terminal, each through their own 240 Ohm resistor
 * - Connect a 4.7 uF capacitor between the + and - terminals of the speaker
 * - Connect speaker GND to Arduino GND
 * - Connect a momentary switch to Pin 8, and the other side of the switch to GND
 */

const byte tone1Pin=12; // pin for tone 1
const byte tone2Pin=13; // pin for tone 2
byte PhoneNumber[]={0}; // for special characters: 10=*, 11=#, 12=1sec delay
byte PhoneNumberLength = 1;  // adjust to length of phone number
byte PhoneNumber1[]={1}; // for special characters: 10=*, 11=#, 12=1sec delay
byte PhoneNumberLength1 = 1;  // adjust to length of phone number
const byte buttonPin=11; // for momentary switch
const byte buttonPin0=0; // dial 0
const byte buttonPin1=1; // dial 1 
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

// frequencies adopted from: https://en.wikipedia.org/wiki/Dual-tone_multi-frequency_signaling
int DTMF[13][2]={
  {941,1336}, // frequencies for touch tone 0
  {697,1209}, // frequencies for touch tone 1
  {697,1336}, // frequencies for touch tone 2
  {697,1477}, // frequencies for touch tone 3
  {770,1209}, // frequencies for touch tone 4
  {770,1336}, // frequencies for touch tone 5
  {770,1477}, // frequencies for touch tone 6
  {852,1209}, // frequencies for touch tone 7
  {852,1336}, // frequencies for touch tone 8
  {852,1477}, // frequencies for touch tone 9
  {941,1209}, // frequencies for touch tone *
  {941,1477}, // frequencies for touch tone #
  {0,0} // pause
};

void setup()
{  
  pinMode(tone1Pin,OUTPUT); // Output for Tone 1
  pinMode(tone2Pin,OUTPUT); // Output for Tone 2
  pinMode(buttonPin,INPUT_PULLUP); // Button
  pinMode(buttonPin0,INPUT_PULLUP); // Button 0
  pinMode(buttonPin1,INPUT_PULLUP); // Button 1
}

void loop(){
  char key = keypad.getKey();
   if(key !=0==HIGH){  // If the button is pushed
      dialNumber(PhoneNumber,PhoneNumberLength);  // Dial the number 0
  
}

  if(key !=1==LOW){  // If the button is pushed
      dialNumber(PhoneNumber1,PhoneNumberLength1);  // Dial the number 1
  }
}


void playDTMF(byte digit, byte duration){
  boolean tone1state=false;
  boolean tone2state=false;
  int tone1delay=(500000/DTMF[digit][0])-10; // calculate delay (in microseconds) for tone 1 (half of the period of one cycle). 10 is a fudge factor to raise the frequency due to sluggish timing.
  int tone2delay=(500000/DTMF[digit][1])-10; // calculate delay (in microseconds) for tone 2 (half of the period of one cycle). 10 is a fudge factor to raise the frequency due to sluggish timing.
  unsigned long tone1timer=micros();
  unsigned long tone2timer=micros();
  unsigned long timer=millis(); // for timing duration of a single tone
  if(digit==12){
    delay(1000); // one second delay if digit is 12
  } else {
    while(millis()-timer<duration){
      if(micros()-tone1timer>tone1delay){
        tone1timer=micros(); // reset the timer
        tone1state=!tone1state; // toggle tone1state
        digitalWrite(tone1Pin, tone1state);
      }
      if(micros()-tone2timer>tone2delay){
        tone2timer=micros(); // reset the timer
        tone2state=!tone2state; // toggle tone2state
        digitalWrite(tone2Pin, tone2state);
      }
    }
    digitalWrite(tone1Pin,LOW);
    digitalWrite(tone2Pin,LOW);
  }
}

void dialNumber(byte number[],byte len){
  for(int i=0;i<len;i++){
    playDTMF(number[i], 100);  // 100 msec duration of tone
    delay(100); // 100 msec pause between tones
  }
}
//END OF FILE

This is not what you want to do:

if(key !=0==HIGH){

this will resolve left to right, just like regular math, so it becomes two compares.

result1 = (key != 0)
if (result1 == HIGH)

whenever any button is pressed then key will not be equal to 0, though it may be the character '0' which is not the same thing. So any time any key is pressed, result1 will be 1, which happens to be what HIGH is defined as so it seems like it kinda works, but just by luck really.

Check out the documentation on if statements to see what good ones look like.

The link I already posted to a different keypad example has almost exactly what you want in the switch statement in the function called keypadEvent. Note that each of the switch's case statements refer to a character '0' not a number 0. The single quotes matter.

switch (key) {
case '0': 
  //do something here.
  break;
case '1':
  //do something else here
  break;
}

bDeters:
This is not what you want to do:

if(key !=0==HIGH){

this will resolve left to right, just like regular math, so it becomes two compares.

result1 = (key != 0)
if (result1 == HIGH)

whenever any button is pressed then key will not be equal to 0, though it may be the character '0' which is not the same thing. So any time any key is pressed, result1 will be 1, which happens to be what HIGH is defined as so it seems like it kinda works, but just by luck really.

Check out the documentation on if statements to see what good ones look like.

The link I already posted to a different keypad example has almost exactly what you want in the switch statement in the function called keypadEvent. Note that each of the switch's case statements refer to a character '0' not a number 0. The single quotes matter.

switch (key) {

case '0':
  //do something here.
  break;
case '1':
  //do something else here
  break;
}

Thanks very much, I much appreciate your help and patience with my misunderstanding.