subroutines:
void printdisplay() // send display array to LED display
{
digitalWrite(LATCH_PIN, LOW);
byte k = chardata[disp[4]];
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, k);
k = chardata[disp[3]];
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, k);
k = chardata[disp[2]];
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, k);
k = chardata[disp[1]];
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, k);
k = chardata[disp[0]];
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, k);
digitalWrite(LATCH_PIN, HIGH);
}
void blankdisplay() //turn display off
{
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, 0);
digitalWrite(LATCH_PIN, HIGH);
}
void cleardisplay() // clear display
{
disp[0] = 20;
disp[1] = 20;
disp[2] = 20;
disp[3] = 20;
disp[4] = 20;
dispd = 0;
flashes = 0;
}
void readmem() // read memory location
{
int e = 0;
while ( e == 0)
{
char mkey = keypad.getKey();
if (mkey != NO_KEY)
{
int digit = keynum(mkey);
if (digit < 10)
{
for (int location = 0; location < 5; location++)
{ // fill disp array
disp[location] = EEPROM.read(digit*6+location);
}
dispd = EEPROM.read(digit*6+5); //what digit we were editing
}
e = 1;
printdisplay();
delay (300); // give us time to get our finger off the button
}
}
}
void recordmem() // save memory location
{
int e = 0;
while ( e == 0)
{
char mkey = keypad.getKey();
if (mkey != NO_KEY)
{
int digit = keynum(mkey);
if (digit < 10)
{
for (int location = 0; location < 5; location++)
{
if (EEPROM.read((digit*6+location) != disp[location]))
{
EEPROM.write((digit*6+location),disp[location]);
}
}
if (EEPROM.read((digit*6+5) != dispd))
{
EEPROM.write((digit*6+5),dispd);
}
}
e = 1;
printdisplay();
delay (300);
}
}
}
void dash() //add dash to digit
{
if (dispd > 0)
{
if (disp[(dispd-1)] < 10 )
{ // only do it if no dash is present
disp[(dispd -1)] = disp[(dispd-1)] +10;
}
}
}
int keynum (char key) // convert keypad char to int varable
{
int number = 10;
switch (key)
{
case '0':
number = 0;
break;
case '1':
number = 1;
break;
case '2':
number = 2;
break;
case '3':
number = 3;
break;
case '4':
number = 4;
break;
case '5':
number = 5;
break;
case '6':
number = 6;
break;
case '7':
number = 7;
break;
case '8':
number = 8;
break;
case '9':
number = 9;
break;
}
return number;
}