Hello,
I am not very confortable with coding but I have been given an accordion left hand keyboard. I have successfully managed to make the matrix work, I can display which row and columns are keyd but I cannont access to the array I have set up.
If someone could help, I can feel it is simple.
I use this library to interact with the matrix
https://github.com/ReneRichterDE/ButtonMatrix
here is the arduino sketch :
/**
*****************************************************************************
Module ButtonMatrix
@file Example02_fell_rose.ino
-----------------------------------------------------------------------------
@brief Example showing basic button matrix usage with
the rose(), fell() and isLongPress(..) methods of a button
-----------------------------------------------------------------------------
@author Rene Richter
@date 21.01.2024
@modified -
@copyright (c) 2023-2024 Rene Richter
@license This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; version
2.1 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
*****************************************************************************
*/
/**
* What you need to do to work with ButtonMatrix:
*
* 1. Add the library to your project
* 2. Include the header file in main.ino/main.cpp (or wherever you need it)
* 3. Either add "using namespace RSys;" or just prefix all ButtonMatrix types with "RSys::" (i.e. "RSys::Button")
* 4. Define the column pins
* 5. Define the row pins
* 6. Define your buttons
* 7. Create an instance of the ButtonMatrix passing the information of steps 4. to 6.
* 8. Make sure to call the init() method in setup()
* 9. Place a call to the update() method in loop() always before dealing with the state of the buttons
*/
#include <Arduino.h>
#include "ButtonMatrix.h" /** Include this header in order to work with the button matrix */
/** Everything in the ButtonMatrix library is within this namespace */
using namespace RSys;
static const uint32_t c_uiMonitorBaud = 115200; // USB monitoring baud rate
// -------------
// Button matrix
// -------------
const uint16_t longPressDuration = 1000; /** Minimum duration of a long press */
const uint8_t COLS = 4; /** Number of button matrix columns */
const uint8_t ROWS = 6; /** Number of button matrix rows */
uint8_t colPins[COLS] = {8,9,10,11}; /** Button matrix column pins */
uint8_t rowPins[ROWS] = {2,3,4,5,6,7}; /** Button matrix row pins */
/** Button matrix button definitons */
Button buttons[ROWS][COLS] = {
{ ("mi"), ("sib"), ("MI"), ("SIb") },
{ ("la"), ("mib"), ("LA"), ("MIb") },
{ ("re"), ("lab"), ("RE"), ("LAb") },
{ ("sol"), ("dod"), ("SOL"), ("DOd") },
{ ("do"), ("fad"), ("DO"), ("FAd") },
{ ("fa"), ("si"), ("FA"), ("SI") }
};
ButtonMatrix matrix((Button*)buttons, rowPins, colPins, ROWS, COLS);
void setup()
{
Serial.begin(c_uiMonitorBaud);
matrix.init(); /** Initialize the ButtonMatrix*/
//matrix.setInvertInput(); /** Uncomment if you get a pressed signal while button is released and vice versa */
}
void loop(){
//-----------------------------------------------------------------------------
Button* pButton = NULL;
if (matrix.update())
{
for (uint8_t row = 0; row < ROWS; row++)
{
for (uint8_t col = 0; col < COLS; col++)
{
pButton = matrix.getButton(row,col);
if (pButton->fell())
{
Serial.print ("row");
Serial.print (row);
Serial.print (" ");
Serial.print ("col");
Serial.println (col);
}
}
}
}
}
and the keyboard