#include <Keypad.h>
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {14,15,16,17};
byte colPins[COLS] = {18,19,20,21};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
unsigned char Digits[12] = {
0xC0, // 0 -> 1100 0000
0xF9, // 1 -> 1111 1001
0xA4, // 2 -> 1010 0100
0xB0, // 3 -> 1011 0000
0x99, // 4 -> 1001 1001
0x92, // 5 -> 1001 0010
0x82, // 6 -> 1000 0010
0xF8, // 7 -> 1111 1000
0x80, // 8 -> 1000 0000
0x90, // 9 -> 1001 0000
0x00, // All On
0xFF // All Off
};
void shiftAll(byte send_to_address, byte send_this_data)
{
digitalWrite(10, LOW);
for (int i = 0; i < 16; i++) {
shiftOut(11, 13, MSBFIRST, send_to_address);
shiftOut(11, 13, MSBFIRST, send_this_data);
}
digitalWrite(10, HIGH);
}
//void setup() {
// Serial.begin(115200);
// pinMode(CLK, OUTPUT);
// pinMode(DIN, OUTPUT);
// pinMode(CS, OUTPUT);
// Setup each MAX7219
// shiftAll(0x0f, 0x00); //display test register - test mode off
// shiftAll(0x0b, 0x07); //scan limit register - display digits 0 thru 7
// shiftAll(0x0c, 0x01); //shutdown register - normal operation
// shiftAll(0x0a, 0x0f); //intensity register - max brightness
//}
void setup(){
Serial.begin(9600);
DDRC = 0xFF;
DDRB |= 0xBF;
PORTC = Digits[10];
PORTB &=~ 0x0F;
PORTB |= 0x01;
shiftAll(0x0f, 0x00); //display test register - test mode off
shiftAll(0x0b, 0x07); //scan limit register - display digits 0 thru 7
shiftAll(0x0c, 0x01); //shutdown register - normal operation
shiftAll(0x0a, 0x0f); //intensity register - max brightness
}
void loop(){
char customKey = customKeypad.getKey();
if (customKey){
if(customKey == '0') {
PORTC = Digits[0];
}
else if(customKey == '1') {
PORTC = Digits[1];
}
else if(customKey == '2') {
PORTC = Digits[2];
}
else if(customKey == '3') {
PORTC = Digits[3];
}
else if(customKey == '4') {
PORTC = Digits[4];
}
else if(customKey == '5') {
PORTC = Digits[5];
}
else if(customKey == '6') {
PORTC = Digits[6];
}
else if(customKey == '7') {
PORTC = Digits[7];
}
else if(customKey == '8') {
PORTC = Digits[8];
}
else if(customKey == '9') {
PORTC = Digits[9];
}
else if(customKey == 'A') {
PORTB &=~ 0x0F;
PORTB |= 0x01;
}
else if(customKey == 'B') {
PORTB &=~ 0x0F;
PORTB |= 0x02;
}
else if(customKey == 'C') {
PORTB &=~ 0x0F;
PORTB |= 0x04;
}
else if(customKey == 'D') {
PORTB &=~ 0x0F;
PORTB |= 0x08;
}
Serial.println(customKey);
}
}