Matrix keyboard to MCP4725

Hello, I am new to Arduino programming, spend my life to electronics, I am 65, but not this, try different things for the last months but no luck, maybe someone can help me. I can post the last code I try'd.
Thank you

#include <Keypad.h>

#include <Adafruit_MCP4725.h>

#define MCP4725_ADDR 0x60   

Adafruit_MCP4725 dac;


//number of rows on the keypad
//number of columns on the keypad
const byte numRows= 8; 
const byte numCols= 5; 


//Code that shows the keypad connections to the arduino terminals
byte colPins[numCols] = {10, 11, 12, A0, A1}; //Collums 0 tot 4
byte rowPins[numRows]= { 9, 8, 7, 6, 5, 4, 3, 2}; //Rows 0 tot 7


//keymap defines the key pressed according to the row and columns just as appears on the keypad
uint16_t keymap[numRows][numCols]=
{
 68,  614, 1161, 1707, 2253,
137,  683, 1229, 1775, 2321,
205,  751, 1297, 1843, 2389,
273,  819, 1365, 1911, 2458,
341,  887, 1434, 1978, 2526,
410,  956, 1502, 2048,
478, 1024, 1570, 2116,      
};


//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void setup()
{
  // initialize the serial communication:
  Serial.begin(115200);
  Wire.begin();
  dac.begin(0x60);

}


void loop()
{
  
  
  uint16_t KeyPadNum = myKeypad.getKey(); 

  
  if (KeyPadNum != NO_KEY)
    {
     // Serial.println(KeyPadNum);

      Serial.println(KeyPadNum);
        
  Wire.beginTransmission (MCP4725_ADDR);
  Wire.write(64);

  //output to DAC 0-4096   
    dac.setVoltage(KeyPadNum, false);

      
     }

      

      }

What does the code actually do? How is that different from what you want?

Your code would be easier to read and follow if you were to format the code with the IDE autoformat tool (ctrl-t or Tools, Auto Format) and remove the excess white spaces.

That does not look right for a declaration and initialization of a 2D array of 8 arrays of 5 elements each.

Here is the declaration from on of the Keypad library examples (4 arrays of 3 elements each):

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','#'}
};

Are you seeing your key presses at least?

Have you tried using the DAC with a simple example sketch you didn't write or mess with too much?

That does not look right for a declaration and initialization of a 2D array of 8 arrays of 5 elements each.

You should supply all the values of the array.

So you want a keypress to set an output voltage, yeah?

a7

Thank you, sorry I had to be more clear.
I tested the DAC works with a sin table.

I have a 37 key keyboard and I want 1V/okt output from the DAC for my synthesizer.

Next time I try to post my code another way.

Did forgot something in array.

#include <Keypad.h>

#include <Adafruit_MCP4725.h>

#define MCP4725_ADDR 0x60   

Adafruit_MCP4725 dac;


//number of rows on the keypad
//number of columns on the keypad
const byte numRows= 8; 
const byte numCols= 5; 


//Code that shows the keypad connections to the arduino terminals
byte colPins[numCols] = {10, 11, 12, A0, A1}; //Collums 0 tot 4
byte rowPins[numRows]= { 9, 8, 7, 6, 5, 4, 3, 2}; //Rows 0 tot 7


//keymap defines the key pressed according to the row and columns just as appears on the keypad
uint16_t keymap[numRows][numCols]=
{
{ 68,  614, 1161, 1707, 2253},
{137,  683, 1229, 1775, 2321},
{205,  751, 1297, 1843, 2389},
{273,  819, 1365, 1911, 2458},
{341,  887, 1434, 1978, 2526},
{410,  956, 1502, 2048},
{478, 1024, 1570, 2116},      
};


//initializes an instance of the Keypad class
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void setup()
{
  // initialize the serial communication:
  Serial.begin(115200);
  Wire.begin();
  dac.begin(0x60);

}


void loop()
{
  
  
  uint16_t KeyPadNum = myKeypad.getKey(); 

  
  if (KeyPadNum != NO_KEY)
    {
     // Serial.println(KeyPadNum);

      Serial.println(KeyPadNum);
        
  Wire.beginTransmission (MCP4725_ADDR);
  Wire.write(64);

  //output to DAC 0-4096   
    dac.setVoltage(KeyPadNum, false);

      
     }

      

      }

'keymap' has to be bytes. You are trying to make each key a 16-bit value. You would have to make a number of changes to the Keypad library to do that.

Solution: Just assign your keys arbitrary letters and then map the letters to the desired numbers:

uint8_t keymap[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijk";

uint16_t VoltageValues [40] =
{
 68,  614, 1161, 1707, 2253,
137,  683, 1229, 1775, 2321,
205,  751, 1297, 1843, 2389,
273,  819, 1365, 1911, 2458,
341,  887, 1434, 1978, 2526,
410,  956, 1502, 2048,
478, 1024, 1570, 2116 
};
  if (KeyPadNum != NO_KEY)
  {
    int index = -1;
    if (KeyPadNum >= 'A' && KeyPadNum <= 'Z')
      index = KeyPadNum - 'A'; // 0 - 25
    if (KeyPadNum >= 'a' && KeyPadNum <= 'k')
      index = KeyPadNum - 'a' + 26; // 26 - 36
    if (index != -1)
    {

      Serial.println(VoltageValues[index]);

In the values array

uint16_t VoltageValues [35] =
{
 68,  614, 1161, 1707, 2253,
137,  683, 1229, 1775, 2321,
205,  751, 1297, 1843, 2389,
273,  819, 1365, 1911, 2458,
341,  887, 1434, 1978, 2526,
410,  956, 1502, 2048, 999,
478, 1024, 1570, 2116, 999
};

I put the 999s in there otherwise the incomplete rows throw off the map.

Maybe they should be something else.

a7

Thank jou, I did try some things but it is not working, I think the keyboard has the good connections because it works with the , multikey file.
I post the code as it is.

#include <Keypad.h>

#include <Adafruit_MCP4725.h>

#define MCP4725_ADDR 0x60

Adafruit_MCP4725 dac;


//number of rows on the keypad
//number of columns on the keypad
const byte numRows = 8;
const byte numCols = 5;


//Code that shows the keypad connections to the arduino terminals
byte colPins[numCols] = {10, 11, 12, A0, A1}; //Collums 0 tot 4
byte rowPins[numRows] = { 9, 8, 7, 6, 5, 4, 3, 2}; //Rows 0 tot 7


//keymap defines the key pressed according to the row and columns just as appears on the keypad
byte keymap[numRows][numCols] =

{
  {'A', 'I', 'Q', 'Y', 'g'},
  {'B', 'J', 'R', 'Z', 'h'},
  {'C', 'K', 'S', 'a', 'i'},
  {'D', 'L', 'T', 'b', 'j'},
  {'E', 'M', 'U', 'c', 'k'},
  {'F', 'N', 'V', 'd'},
  {'G', 'O', 'W', 'e'},
  {'H', 'P', 'X', 'f'},
};
//uint8_t keymap[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijk";


uint16_t VoltageValues [40] =
{
  68,  614, 1161, 1707, 2253,
  137,  683, 1229, 1775, 2321,
  205,  751, 1297, 1843, 2389,
  273,  819, 1365, 1911, 2458,
  341,  887, 1434, 1980, 2526,
  410,  956, 1502, 2048, 2594,
  478, 1024, 1570, 2116, 2662,
  564, 1092, 1638, 2185, 2731,
};


//initializes an instance of the Keypad class
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void setup()
{
  // initialize the serial communication:
  Serial.begin(115500);
  Wire.begin();
  dac.begin(0x60);

}


void loop()
{


  byte KeyPadNum = myKeypad.getKey();


  if (KeyPadNum != NO_KEY)
  {
    int index = -1;
    if (KeyPadNum >= 'A' && KeyPadNum <= 'Z')
      index = KeyPadNum - 'A'; // 0 - 25
    if (KeyPadNum >= 'a' && KeyPadNum <= 'k')
      index = KeyPadNum - 'a' + 26; // 26 - 36
    if (index != -1)

    {
      Serial.println(VoltageValues[index]);

      // Wire.beginTransmission (MCP4725_ADDR);
      // Wire.write(64);

      //output to DAC 0-4096
      dac.setVoltage(VoltageValues, false);
    }

  }
}

"not working" in what way?

Why are you not using `VoltageValues[index]'?

Sorry, did not see that, I try tomorrow. Do you think the rest looks good. Thank you for the reaction

You don't use this value so you're using the default address: 0x62. If your chip is set for address 0x60 you will need to change:
Adafruit_MCP4725 dac;
to
Adafruit_MCP4725 dac(MCP4725_ADDR);

Thank you, now I have readings in the serial monitor but have a few errors.

#include <Keypad.h>

#include <Adafruit_MCP4725.h>

#define MCP4725_ADDR 0x60

Adafruit_MCP4725 dac(MCP4725_ADDR);


//number of rows on the keypad
//number of columns on the keypad
const byte numRows = 8;
const byte numCols = 5;


//Code that shows the keypad connections to the arduino terminals
byte colPins[numCols] = {A2, A1, A0, 11, 10}; //Collums 0 tot 4
byte rowPins[numRows] = { 9, 8, 7, 6, 5, 4, 3, 2}; //Rows 0 tot 7


//keymap defines the key pressed according to the row and columns just as appears on the keypad
uint8_t keymap[numRows][numCols] =

{
  {'A', 'I', 'Q', 'Y', 'g'},
  {'B', 'J', 'R', 'Z', 'h'},
  {'C', 'K', 'S', 'a', 'i'},
  {'D', 'L', 'T', 'b', 'j'},
  {'E', 'M', 'U', 'c', 'k'},
  {'F', 'N', 'V', 'd'},
  {'G', 'O', 'W', 'e'},
  {'H', 'P', 'X', 'f'},
};
//uint8_t keymap[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijk";


uint16_t VoltageValues [40] =
{
  68,  614, 1161, 1707, 2253,
  137,  683, 1229, 1775, 2321,
  205,  751, 1297, 1843, 2389,
  273,  819, 1365, 1911, 2458,
  341,  887, 1434, 1980, 2526,
  410,  956, 1502, 2048, 2594,
  478, 1024, 1570, 2116, 2662,
  564, 1092, 1638, 2185, 2731,
};


//initializes an instance of the Keypad class
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
  Wire.begin();
  dac.begin(0x60);

}


void loop()
{


  byte KeyPadNum = myKeypad.getKey();


  if (KeyPadNum != NO_KEY)
  {
    int index = -1;
    if (KeyPadNum >= 'A' && KeyPadNum <= 'Z')
      index = KeyPadNum - 'A'; // 0 - 25
    if (KeyPadNum >= 'a' && KeyPadNum <= 'k')
      index = KeyPadNum - 'a' + 26; // 26 - 36
    if (index != -1)

    {
      Serial.println(VoltageValues[index]);

      // Wire.beginTransmission (MCP4725_ADDR);
      // Wire.write(64);

      //output to DAC 0-4096
      dac.setVoltage(VoltageValues[index]);
    }

  }
}

key_dac4:7:34: error: no matching function for call to 'Adafruit_MCP4725::Adafruit_MCP4725(int)'

Adafruit_MCP4725

C:\Users\eepva\Documents\key_dac4\key_dac4.ino: In function 'void loop()':

key_dac4:86:42: error: no matching function for call to 'Adafruit_MCP4725::setVoltage(uint16_t&)'

   dac.setVoltage(VoltageValues[index]);

                                      ^

In file included from C:\Users\eepva\Documents\key_dac4\key_dac4.ino:3:0:

C:\Users\eepva\Documents\Arduino\libraries\Adafruit_MCP4725/Adafruit_MCP4725.h:30:8: note: candidate: bool Adafruit_MCP4725::setVoltage(uint16_t, bool, uint32_t)

Check your example code, I will also.

That function needs to know which of the two converters you are talking to, or something else dunno.

bool setVoltage(uint16_t output, bool writeEEPROM,
                  uint32_t dac_frequency = 400000);

Use

 setVoltage(VoltageValues[index], false);

from the example. The third argument can be omitted as it has a default value that is used.

HTH

OK, that false just means don't write the set value into EEPROM. From the Adafruit product page:

There's an EEPROM so if you write the output voltage, you can 'store it' so if the device is power cycled it will restore that voltage.

a7

Oops. Looks like the device address is set in .begin() and not in the constructor.

Change this:
Adafruit_MCP4725 dac(MCP4725_ADDR);
back to:
Adafruit_MCP4725 dac;

and, to use the MCP4725_ADDR value, change:
dac.begin(0x60);
to
dac.begin(MCP4725_ADDR);

Thank you both, works great now.
It would take me weeks to find that out, or never ;-), post the code working, maybe for someone else.

#include <Keypad.h>

#include <Adafruit_MCP4725.h>

#define MCP4725_ADDR 0x60

Adafruit_MCP4725 dac;


//number of rows on the keypad
//number of columns on the keypad
const byte numRows = 8;
const byte numCols = 5;


//Code that shows the keypad connections to the arduino terminals
byte colPins[numCols] = {A2, A1, A0, 11, 10}; //Collums 0 tot 4
byte rowPins[numRows] = { 9, 8, 7, 6, 5, 4, 3, 2}; //Rows 0 tot 7


//keymap defines the key pressed according to the row and columns just as appears on the keypad
uint8_t keymap[numRows][numCols] =

{
  {'A', 'I', 'Q', 'Y', 'g'},
  {'B', 'J', 'R', 'Z', 'h'},
  {'C', 'K', 'S', 'a', 'i'},
  {'D', 'L', 'T', 'b', 'j'},
  {'E', 'M', 'U', 'c', 'k'},
  {'F', 'N', 'V', 'd'},
  {'G', 'O', 'W', 'e'},
  {'H', 'P', 'X', 'f'},
};


uint16_t VoltageValues [40] =

{
  68,  137, 205, 273, 341,
  410,  478, 564, 614, 683,
  751,  819, 887, 956, 1024,
  1092, 1161, 1229, 1297, 1365,
  1434, 1502, 1570, 1638, 1707,
  1775, 1843, 1911, 1980, 2048,
  2116, 2185, 2253, 2321, 2389,
  2458, 2526, 2594, 2662, 2731,
};


//initializes an instance of the Keypad class
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);
  Wire.begin();
  dac.begin(MCP4725_ADDR);

}


void loop()
{


  byte KeyPadNum = myKeypad.getKey();


  if (KeyPadNum != NO_KEY)
  {
    int index = -1;
    if (KeyPadNum >= 'A' && KeyPadNum <= 'Z')
      index = KeyPadNum - 'A'; // 0 - 25
    if (KeyPadNum >= 'a' && KeyPadNum <= 'k')
      index = KeyPadNum - 'a' + 26; // 26 - 36
    if (index != -1)

    {
      Serial.println(VoltageValues[index]);


      //output to DAC 0-4096
      dac.setVoltage(VoltageValues[index], false);
    }

  }
}

Oops, I find out that the output of the DAC hold its value after release of the button, is it possible it go's to 0volt after release.
I want to add a output pin 13 go high, when I push a button and low by release.
I did try something but it keeps high.

#include <Keypad.h> 

#include <Adafruit_MCP4725.h> 

#define MCP4725_ADDR 0x60 

#define GATE 13    // Arduino Board LED is on Pin 13 
int GATEval = LOW;


Adafruit_MCP4725 dac; 

//number of rows on the keypad //number of columns on the keypad 
const byte numRows = 8; 
const byte numCols = 5; 

//Code that shows the keypad connections to the arduino terminals 

byte colPins[numCols] = {A2, A1, A0, 11, 10}; //Collums 0 tot 4 
byte rowPins[numRows] = { 9, 8, 7, 6, 5, 4, 3, 2}; //Rows 0 tot 7 

//keymap defines the key pressed according to the row and columns just as appears on the keypad 
uint8_t keymap[numRows][numCols] = { 
{'A', 'I', 'Q', 'Y', 'g'}, 
{'B', 'J', 'R', 'Z', 'h'}, 
{'C', 'K', 'S', 'a', 'i'}, 
{'D', 'L', 'T', 'b', 'j'}, 
{'E', 'M', 'U', 'c', 'k'}, 
{'F', 'N', 'V', 'd'}, 
{'G', 'O', 'W', 'e'}, 
{'H', 'P', 'X', 'f'}, 
 }; 

uint16_t VoltageValues [40] =
{ 
 68, 137, 205, 273, 341, 
410, 478, 564, 614, 683,
751, 819, 887, 956, 1024, 
1092, 1161, 1229, 1297, 1365, 
1434, 1502, 1570, 1638, 1707, 
1775, 1843, 1911, 1980, 2048, 
2116, 2185, 2253, 2321, 2389, 
2458, 2526, 2594, 2662, 2731, 
}; 

//initializes an instance of the Keypad class 
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols); 

void setup() 
{ 
// initialize the serial communication: 
Serial.begin(9600); 
Wire.begin(); 
dac.begin(MCP4725_ADDR); 
    
pinMode(GATE, OUTPUT); // Set GATE pin   
} 

void loop() 
{ 
byte KeyPadNum = myKeypad.getKey(); 
    
if (KeyPadNum != NO_KEY) 
{ 
int index = -1; 
 if (KeyPadNum >= 'A' && KeyPadNum <= 'Z')      
 index = KeyPadNum - 'A'; // 0 - 25 
 if (KeyPadNum >= 'a' && KeyPadNum <= 'k')
 index = KeyPadNum - 'a' + 26; // 26 - 36
 if (index != -1)
  
            { Serial.println(VoltageValues[index]);
//output to DAC 0-4096
  dac.setVoltage(VoltageValues[index], false);  
            
digitalWrite(GATE,HIGH);  //Turn GATE on   
               
 } 
else{      
digitalWrite(GATE,LOW);  //Turn GATE off
        } 
    }
 }

See the "EventKeypad" example for how to add an event handler. In the handler, you can tell when a key has been pressed and when a key has been released.

Thank you I look in to it

I did try different things, every time the compiling is oke, but the LED stay's on and also the DAC.
Can you give me a hint.

#include <Keypad.h> 

#include <Adafruit_MCP4725.h> 

#define MCP4725_ADDR 0x60 

Adafruit_MCP4725 dac; 

//number of rows on the keypad //number of columns on the keypad 
const byte numRows = 8; 
const byte numCols = 5; 

//Code that shows the keypad connections to the arduino terminals 

byte colPins[numCols] = {A2, A1, A0, 11, 10}; //Collums 0 tot 4 
byte rowPins[numRows] = { 9, 8, 7, 6, 5, 4, 3, 2}; //Rows 0 tot 7 

//keymap defines the key pressed according to the row and columns just as appears on the keypad 
uint8_t keymap[numRows][numCols] = { 
{'A', 'I', 'Q', 'Y', 'g'}, 
{'B', 'J', 'R', 'Z', 'h'}, 
{'C', 'K', 'S', 'a', 'i'}, 
{'D', 'L', 'T', 'b', 'j'}, 
{'E', 'M', 'U', 'c', 'k'}, 
{'F', 'N', 'V', 'd'}, 
{'G', 'O', 'W', 'e'}, 
{'H', 'P', 'X', 'f'}, 
 }; 

uint16_t VoltageValues [40] =
{ 
 68, 137, 205, 273, 341, 
410, 478, 564, 614, 683,
751, 819, 887, 956, 1024, 
1092, 1161, 1229, 1297, 1365, 
1434, 1502, 1570, 1638, 1707, 
1775, 1843, 1911, 1980, 2048, 
2116, 2185, 2253, 2321, 2389, 
2458, 2526, 2594, 2662, 2731, 
}; 

//initializes an instance of the Keypad class 
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols); 

byte ledPin = 13;
boolean ledPin_state;
byte KeyPadNum;
//boolean blink = false;
//int index;

void setup() 
{ 
// initialize the serial communication: 
Serial.begin(9600); 

dac.begin(MCP4725_ADDR); 
    
pinMode(ledPin, OUTPUT); // Sets the digital pin as output. 
digitalWrite(ledPin, LOW); // Turn the LED off. 
ledPin_state = digitalRead(ledPin); // Store initial LED state. HIGH when LED is on.
myKeypad.addEventListener(keypadEvent); // Add an event listener for this keypad
} 

void loop() 
{ 
byte KeyPadNum = myKeypad.getKey(); 
    
if (KeyPadNum != NO_KEY) 
{ 
int index = -1; 
 if (KeyPadNum >= 'A' && KeyPadNum <= 'Z')      
 index = KeyPadNum - 'A'; // 0 - 25 
 if (KeyPadNum >= 'a' && KeyPadNum <= 'k')
 index = KeyPadNum - 'a' + 26; // 26 - 36
 if (index != -1)
        
{ Serial.println(VoltageValues[index]);
//output to DAC 0-4096
  dac.setVoltage(VoltageValues[index], false);  
            
        } 
    }
 }
// Taking care of some special events.
void keypadEvent(KeypadEvent key){ 
    switch (myKeypad.getState()){ 
        case PRESSED: 
        if (KeyPadNum != NO_KEY); { 
digitalWrite(ledPin,digitalRead(ledPin));
ledPin_state = digitalRead(ledPin); // Remember LED state, lit or unlit. 
            } 
     break;
        case RELEASED: 
        if (KeyPadNum = NO_KEY);
        
{ digitalWrite(ledPin,ledPin_state); // Restore LED state from before it started blinking.
            }
        
       break;   
        
            }
    }

You don't need the LED toggle stuff from the example and all of the keypad action should be in keypadEvent() instead of loop() so you can act differently for PRESSED and RELEASED.

#include <Keypad.h>
#include <Adafruit_MCP4725.h>

const byte MCP4725_ADDR = 0x60;

Adafruit_MCP4725 dac;

//number of rows on the keypad //number of columns on the keypad
const byte numRows = 8;
const byte numCols = 5;

//Code that shows the keypad connections to the arduino terminals

byte colPins[numCols] = {A2, A1, A0, 11, 10}; //Collums 0 tot 4
byte rowPins[numRows] = { 9, 8, 7, 6, 5, 4, 3, 2}; //Rows 0 tot 7

//keymap defines the key pressed according to the row and columns just as appears on the keypad
uint8_t keymap[numRows][numCols] =
{
  {'A', 'I', 'Q', 'Y', 'g'},
  {'B', 'J', 'R', 'Z', 'h'},
  {'C', 'K', 'S', 'a', 'i'},
  {'D', 'L', 'T', 'b', 'j'},
  {'E', 'M', 'U', 'c', 'k'},
  {'F', 'N', 'V', 'd'},
  {'G', 'O', 'W', 'e'},
  {'H', 'P', 'X', 'f'},
};

uint16_t VoltageValues [40] =
{
  68, 137, 205, 273, 341,
  410, 478, 564, 614, 683,
  751, 819, 887, 956, 1024,
  1092, 1161, 1229, 1297, 1365,
  1434, 1502, 1570, 1638, 1707,
  1775, 1843, 1911, 1980, 2048,
  2116, 2185, 2253, 2321, 2389,
  2458, 2526, 2594, 2662, 2731,
};

//initializes an instance of the Keypad class
Keypad myKeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);

byte KeyPadNum;

void setup()
{
  // initialize the serial communication:
  Serial.begin(9600);

  dac.begin(MCP4725_ADDR);

  myKeypad.addEventListener(keypadEvent); // Add an event listener for this keypad
}

void loop()
{
  myKeypad.getKey(); // Check for any new events
}

// Taking care of events.
void keypadEvent(KeypadEvent key)
{
  static int lastIndexPressed = 99;

  // Convert key to index number
  int index = -1;
  if (key >= 'A' && key <= 'Z')
    index = key - 'A'; // 0 - 25
  if (key >= 'a' && key <= 'k')
    index = key - 'a' + 26; // 26 - 36

  switch (myKeypad.getState())
  {
    case PRESSED:
      if (index != -1)
      {
        // A key has just been pressed
        lastIndexPressed = index; // Remember the last key pressed
        Serial.print("Key pre4ssed: ");
        Serial.println(index);
        Serial.println(VoltageValues[index]);
        //output to DAC 0-4096
        dac.setVoltage(VoltageValues[index], false);
      }
      break;

    case RELEASED:
      // A key has just been released
      if (index != -1 && index == lastIndexPressed)
      {
        lastIndexPressed = 99; // Remember the last key pressed
        Serial.print("Key released: ");
        Serial.println(index);
        //output to DAC 0-4096
        dac.setVoltage(0, false);
      }
      break;

    default:  // HOLD and IDLE are not needed.
      break;
  } // End of switch
}