@Graynomad
Did you find a cheap source for those displays or just pull it from an old calculator?
Old calculator ? No They are a 3 digit 7 segments display. I got them for $0.50 ca at Active Surplus. So I got myself a few of those.
It is a fun project. It just help me out to learn in programing, use a keypad and use a MAX7219.
@ CrossRoads
I agree with you. I did look into the keypad.h. I download the library. The small problem with this solution is : Use to many pins. So I was planing to use the 4021. I was planning to build a circuit for a 4 X 5 keypad matrix using the 4021. Beside a byte have 256 combinations. I also look into the use of the chip MAX1234, a touch pad / keypad encoder compatible with SPI <-- will work with shiftIn() too. Datasheet site : http://datasheets.maxim-ic.com/en/ds/MAX1233-MAX1234.pdf I check Mouser.com if they have it, they do, but no DIP version. The chip is QFN. ... I got a little hope with this site. http://www.ezprototypes.com/index.php Click the Chips Adapters and Sockets.
@NI$HANT
Where in you are seeking code help or input?
Both. I am open mind about new code, new help or new ideas. This project is just some kind of "homework".
Updated :
I put the two circuit together. I did a code. It just simply "scroll" a number you press the keypad. When I press nothing, no movement, scrolling. I press a key, a number coresponding the key I press show up. The next key I press show up and place the last key next to it.<-- Shifting the number to the left.
So far, my code I have now, work just fine, but it is the keypad I have an issue with ( I think ) , during the serial monitor, the bits do not all show up. I press a key and a row bit show but no col bit, sometime it show, sometime it does not. Maybe the hex Inverter chip - 74LS04 / 74LS14 maybe not right for the job. I do have in my parts bins a 4049, 74HC04 and 74HC14. I wil see if that will work. With the 4049, I have to re-wired the breadboard setup. I will try to wired directely the keypad to the 4021 chip, code the variable - keydata - invert the data so I can use the code almost as is. If that does not work to well , I will use a LM339 comparator and inverter chip. <-- I know, it is overkill.
Here the code I have so far.
// Keypad Serial pins
const byte latchkeypin = 10;
const byte datakeypin = 12;
const byte clockkeypin = 11;
// Display Serial pins
const byte datadisplaypin = 9;
const byte clockdisplaypin = 8;
const byte latchdisplaypin = 7;
// Anykey pin
const byte anykeypin = 2;
// MAX7419 init data
word initdata[5] = { 0x0C01, 0x0F00, 0x0A0B, 0x0B07, 0x09FF };
// Fill the Display array with a blank code
word display_data[8] = { 0x010F, 0x020F, 0x030F, 0x040F, 0x050F, 0x060F, 0x070F, 0x080F };
volatile boolean keystate;
byte keydata;
byte keynumber;
byte data_box;
void setup()
{
//start serial
Serial.begin(9600);
//define the pins modes
pinMode(latchkeypin, OUTPUT);
pinMode(clockkeypin, OUTPUT);
pinMode(datakeypin, INPUT);
pinMode(datadisplaypin, OUTPUT);
pinMode(clockdisplaypin, OUTPUT);
pinMode(latchdisplaypin, OUTPUT);
pinMode(anykeypin, INPUT);
attachInterrupt(0,anykeypress,RISING);
/* Init the MAX7419 : Normal Mode
Normal Operation
Setting the Intensity
Numbers of Digits being display
Set to Decode Mode
*/
for (int i=0;i<5;i++)
{
digitalWrite(latchdisplaypin, LOW);
shiftOut(datadisplaypin, clockdisplaypin, MSBFIRST, highByte(initdata[i]));
shiftOut(datadisplaypin, clockdisplaypin, MSBFIRST, lowByte(initdata[i]) );
digitalWrite(latchdisplaypin, HIGH);
delay(5);
}
// Blank the display
display_the_numbers();
keystate = 0;
data_box = 1;
}
void loop()
{
data_box = 1;
while ( keystate == 0)
{
// wait for a key press
}
read_keypad();
convert_the_keypad_data();
if ( keynumber < 0x0A )
{
for (int i=7;i>0;i--)
{
display_data[i]=display_data[i-1];
display_data[i] = word ( (i+1) , lowByte( display_data[i] ) );
}
display_data[0] = word ( 1, keynumber );
data_box++;
}
display_the_numbers();
keystate = 0;
//Print out the results.
Serial.print(keydata, BIN);
Serial.print(" ");
Serial.print(keydata, HEX);
Serial.print(" ");
Serial.print(keynumber, HEX);
Serial.print(" ");
Serial.println(keydata, DEC);
//white space
//Serial.println("-------------------");
//delay so all these print satements can keep up.
delay(1000);
//display_the_numbers();
}
void read_keypad()
{
//Pulse the latch pin:
//set it to 1 to collect parallel data
digitalWrite(latchkeypin,HIGH);
//set it to 1 to collect parallel data, wait
delayMicroseconds(20);
//set it to 0 to transmit data serially
digitalWrite(latchkeypin,LOW);
//while the shift register is in serial mode
//collect each shift register into a byte
//the register attached to the chip comes in first
keydata = shiftIn(datakeypin, clockkeypin,LSBFIRST);
}
void convert_the_keypad_data()
{
byte what_row;
what_row = ( keydata >> 3) & 0x0F;
switch ( what_row)
{
case 1:
keynumber = ( ( keydata >> 1 ) & 0x03 ) + 1;
break;
case 2:
keynumber = (( keydata >> 1 ) & 0x03 ) + 4;
break;
case 4:
keynumber = (( keydata >> 1 ) & 0x03 ) + 7;
break;
case 8:
special_key();
break;
}
}
void display_the_numbers()
{
for (int i=0;i<8;i++)
{
digitalWrite(latchdisplaypin, LOW);
shiftOut(datadisplaypin, clockdisplaypin, MSBFIRST, highByte(display_data[i]) );
shiftOut(datadisplaypin, clockdisplaypin, MSBFIRST, lowByte(display_data[i]) );
digitalWrite(latchdisplaypin, HIGH);
delay(5);
}
}
void special_key()
{
byte special_case;
special_case = ( ( keydata >> 1) & 0x03 ) + 1;
switch ( special_case )
{
case 1:
keynumber = 0x0F;
break;
case 2:
keynumber = 0x00;
break;
case 3:
keynumber = 0x0C;
break;
}
}
void anykeypress()
{
keystate = 1;
}