user setup
void keypadEvent(KeypadEvent key) //handle key hold
{
if (keypad.getState() == HOLD)
{
switch (key)
{
case '#': // clear memory
clearmem();
break;
case '*': // set flash count
setflashcount();
break;
case 'a': // set time out
settimeout();
break;
}
}
}
void recalflashcount() // convert flashcount memlocation to int number
{
int fla1 = EEPROM.read(flashcountlocation); // get current flast count
int fla2 = EEPROM.read(flashcountlocation + 1);
flashcount = (fla1*10+fla2);
}
void setflashcount()
{
dispflashcount();
digitalWrite(ledPin, HIGH); // turn the keypress LED on
delay (600); // give us time to get our finger off the button
int e = 0;
while ( e == 0)
{
char mkey = keypad.getKey(); // first digit
if (mkey != NO_KEY)
{
int digit = keynum(mkey);
if (digit < 10)
{
if (EEPROM.read((flashcountlocation) != digit))
{
EEPROM.write((flashcountlocation),digit);
}
e = 1;
}
}
}
dispflashcount();
digitalWrite(ledPin, LOW); // turn the keypress LED off
delay (600); // give us time to get our finger off the button
digitalWrite(ledPin, HIGH); // turn the keypress LED on
e = 0;
while ( e == 0)
{
char mkey = keypad.getKey(); // second digit
if (mkey != NO_KEY)
{
int digit = keynum(mkey);
if (digit < 10)
{
if (EEPROM.read((flashcountlocation + 1) != digit))
{
EEPROM.write((flashcountlocation + 1),digit);
}
e = 1;
}
}
}
dispflashcount();
digitalWrite(ledPin, LOW); // turn the keypress LED off
delay (3000);
cleardisplay();
printdisplay();
}
void settimeout()
{
disptimeout();
digitalWrite(ledPin, HIGH); // turn the keypress LED on
delay (600); // give us time to get our finger off the button
int e = 0;
while ( e == 0)
{
char mkey = keypad.getKey(); // first digit
if (mkey != NO_KEY)
{
int digit = keynum(mkey);
if (digit < 10)
{
if (EEPROM.read((timeoutlocation) != digit))
{
EEPROM.write((timeoutlocation),digit);
}
e = 1;
}
}
}
disptimeout();
digitalWrite(ledPin, LOW); // turn the keypress LED off
delay (600); // give us time to get our finger off the button
digitalWrite(ledPin, HIGH); // turn the keypress LED on
e = 0;
while ( e == 0)
{
char mkey = keypad.getKey(); // second digit
if (mkey != NO_KEY)
{
int digit = keynum(mkey);
if (digit < 10)
{
if (EEPROM.read((timeoutlocation + 1) != digit))
{
EEPROM.write((timeoutlocation + 1),digit);
}
e = 1;
}
}
}
disptimeout();
digitalWrite(ledPin, LOW); // turn the keypress LED off
delay (3000);
cleardisplay();
printdisplay();
}
void dispflashcount()
{
int fla1 = EEPROM.read(flashcountlocation); // get current flast count and display it
int fla2 = EEPROM.read(flashcountlocation + 1);
byte k = chardata[fla2];
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, k);
k = chardata[fla1];
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, k);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B11110111);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B00111000);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B01110001);
}
void recaltimeout() // convert time out memlocation to int number
{
long time1 = EEPROM.read(timeoutlocation); // get time out count
long time2 = EEPROM.read(timeoutlocation + 1);
disp_time = ((time1*10+time2) * 1000);
}
void clearmem()
{
int e =0;
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B00111001); // are you sure?
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B00000000);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B11010000);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B00111000);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B00111001);
delay (600); // give us time to get our finger off the button
while ( e == 0)
{
char mkey = keypad.getKey();
if (mkey != NO_KEY)
{
switch (mkey)
{
case 'c':
for (int loc = 0; loc < 10; loc++)
{
for (int location = 0; location < 5; location++)
{
if (EEPROM.read((loc*6+location) != 20))
{
EEPROM.write((loc*6+location),20);
}
}
if (EEPROM.read((loc*6+5) != 0))
{
EEPROM.write((loc*6+5),0);
}
}
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B01011110); // display mem clear
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B01111001);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B01010000);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B00111000);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B00111001);
delay (3000);
e = 1;
break;
default:
e = 1;
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B00000000); // display mem not clear
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B01111001);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B01110001);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B01110111);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B01101101);
delay (3000);
break;
}
}
}
}
void disptimeout()
{
int time1 = EEPROM.read(timeoutlocation); // get current display time out and display it
int time2 = EEPROM.read(timeoutlocation + 1);
byte k = chardata[time2];
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, k);
k = chardata[time1];
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, k);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B11101101);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B00010000);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, B01011110);
}