I made the button box. It's working now. But I want to use six or more led with this box. I have arduino leonardo. I will connect analog input because 9 pin used. Empty pins is A0-A1-A2-A3-A4-A5-A6-7-12-13. How I do? I also have two 74HC595 integrated.
My code is ;
#include <Keyboard.h>
// Array of pins for the columns
int cPins[] = {2, 3, 4, 5, 6};
// Number of pins in the column array
int cPinsNo = 5;
// Array of pins for the rows
int rPins[] = {8, 9, 10, 11};
// Number of pins in the row array
int rPinsNo = 4;
// Array for the last known switch states [cPinsNo][rPinsNo]
int colPrev[5][4] = {0};
uint8_t buttonCodes[5][4] = {
{0x61, 0x62, 0x63, 0x64},
{0x65, 0x66, 0x67, 0x68},
{0x69, 0x70, 0x71, 0x72},
{0x73, 0x74, 0x75, 0x76},
{0x77, 0x78, 0x79, 0x7A}
};
void setup()
{
Serial.begin(9600);
for(int cPin = 0; cPin < cPinsNo; cPin++)
{
pinMode(cPins[cPin], OUTPUT);
digitalWrite(cPins[cPin], HIGH);
}
for(int rPin = 0; rPin < rPinsNo; rPin++)
{
pinMode(rPins[rPin], INPUT);
digitalWrite(rPins[rPin], HIGH);
}
}
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++)
{
if(digitalRead(rPins[rPin]) == LOW)
{
if(colPrev[cPin][rPin] == 0)
{
Keyboard.press(buttonCodes[cPin][rPin]);
delay(150);
Keyboard.release(buttonCodes[cPin][rPin]);
colPrev[cPin][rPin] = 1;
}
}
else {
if(colPrev[cPin][rPin] == 1)
{
colPrev[cPin][rPin] = 0;
}
}
}
digitalWrite(cPins[cPin], HIGH);
}
}
It's working now. I want to add six led or more.