PaulS you are a legend this helps me confirm earlier thinking i was supposed to setup another array i just made the error of repeating it as uint8_t not char.
But i am still close yet so far away, at the moment my below code does show a different output between what is wrote into note pad when a button is pressed vs what is shown on LCD print - but it appears to be showing the … well i dont know it appears to be the row or colum rather than the text from the array.
// Array of pins for the columns
int cPins[] = {A0, A1, A2, A3, A4};
// Number of pins in the column array
int cPinsNo = 5;
// Array of pins for the rows
int rPins[] = {9, 8, 7, 6};
// Number of pins in the row array
int rPinsNo = 4;
// Array for the last known switch states [cPinsNo][rPinsNo]
int colPrev[5][4] = {0};
// Key codes to be used for each button
// (see table above for codes to use)
// (columns and rows are transposed on device)
uint8_t buttonCodes[5][4] = {
{0x30, 0x31, 0x32, 0x33},
{0x34, 0x35, 0x36, 0x37},
{0x38, 0x39, 0x27, 0x2C},
{0x2D, 0x2E, 0x2F, 0x3B},
{0x5B, 0x5D, 0xD8, 0xD7}
};
#include "buttonname.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
//Start Serial
lcd.begin(20, 4);
lcd.print("Title");
lcd.setCursor(0, 2);
lcd.print("Recently Pressed :");
Serial.begin(9600);
for(int cPin = 0; cPin < cPinsNo; cPin++)
{
pinMode(cPins[cPin], OUTPUT);
digitalWrite(cPins[cPin], HIGH);
}
//Set the Row Pin Mode
Serial.println("Setting Row Pins...");
for(int rPin = 0; rPin < rPinsNo; rPin++)
{
pinMode(rPins[rPin], INPUT);
digitalWrite(rPins[rPin], HIGH);
}
Serial.println("Ready!");
}
void loop()
{
// Loop through the columns
for(int cPin = 0; cPin < cPinsNo; cPin++)
{
digitalWrite(cPins[cPin], LOW);
// Loop through the rows
for(int rPin = 0; rPin < rPinsNo; rPin++)
{
//Check if each switch is pressed
if(digitalRead(rPins[rPin]) == LOW)
{
// Check to see if the state has changed since last time
if(colPrev[cPin][rPin] == 0)
{
// Do action here, switch is on
Serial.print(cPins[cPin]);
Serial.print(", ");
Serial.print(rPins[rPin]);
Serial.println(" ON");
Keyboard.press(buttonCodes[cPin][rPin]);
delay(250);
Keyboard.release(buttonCodes[cPin][rPin]);
lcd.setCursor(0, 3);
lcd.print(buttonName[cPin][rPin]);
// Update last known state of this switch
colPrev[cPin][rPin] = 1;
}
}
else {
// Check to see if the state has changed since last time
if(colPrev[cPin][rPin] == 1)
{
// Do action here, switch is off
Serial.print(cPins[cPin]);
Serial.print(", ");
Serial.print(rPins[rPin]);
Serial.println(" OFF");
// Update last known state of this switch
colPrev[cPin][rPin] = 0;
}
}
}
digitalWrite(cPins[cPin], HIGH);
}
}
char buttonName[5][4] = {
{'testA1', 'testA2', 'testA3', 'testA4'},
{'testB1', 'testB2', 'testB3', 'testB4'},
{'testC1', 'testC2', 'testC3', 'testC4'},
{'testD1', 'testD2', 'testD3', 'testD4'},
{'testE1', 'testE2', 'testE3', 'testE4'}
};
At the moment if i press the button that corresponds to {0x5B, 0x5D i get the [ and ] as output in note pad and in LCD Print i get 1 and 2 - i guess this means Row 1 and Row 2 (but why no reference to Column 5?)
lcd.print(buttonName[cPin][rPin]);
The above i would have figured would call
testE1 and testE2 being that the code is supposed to be referencing “buttonName” colum 5 x 1 and 5 x 2 isnt it?
By the way when i used " not ’ i got errors that when i did some research were cleared up so it would compile - could this be the cause of why it isn’t showing the text “testE1”?? This was the error.
error: initializer-string for array of chars is too long [-fpermissive]