Organize and Share your Electronics the way you want. Sign-Up for a free account now. It takes only 30 seconds!

OpenAccess Keypad functions

OpenAccess Keypad functions

char keypad_matrix()

{
//Serial.println(“keypad_matrix”);
if(Serial3.available())
{
char result = Serial3.read();//Read key press
return result;
}
else
{
return ‘ ‘;//equivalent to -1, a null result
}
//delay(10);
}

This code polls for keypresses.  If it returns anything then the keypresses are acted on.  Stuff like this is why it is so important to keep the code looping and not blocking.  If there are multiple keypresses buffered this will grab one and leave the rest for next loop.

void enter_pin(char c)
{
//Serial.print(“Pin Button = “);
//Serial.println(reader2);
LCD_disp(“*”);
pin[digit] = c – ‘0’;//stores as numbers rather than characters
digit++;
}

Here is how a pin is incremented, it is one of the few places I do not overwrite the entire LCD line at once.

void backspace_pin()
{
pin[digit] = 15;
//Serial.println(“backspace”);
LCD_displn(” “,1);
LCD_displn(“Pin:”,1);
if(digit >0)
{
digit–;
pin[digit] = 15;
}
for (int i = 0;i<digit;i++)//repopulates asterisks
{
LCD_disp(“*”);
}
//for(int i=0;i<(sizeof(pin)/sizeof(pin[0]));i++)
//{
// Serial.print(pin[i]);
//}
}

Removing a digit is tricky, I have to set it to an impossible to type character and rewrite the line of asterisks because I don’t support arbitrary cursor positioning.

 

void clear_pin()
{
digit = 0;
for(int i=0;i<(sizeof(pin)/sizeof(pin[0]));i++)
{
pin[i] = 15;
}
}

Clearing a pin is easy, set back to unprintable.  These steps are done in the key taking process which is longer and in the main logic code.  This is part of the greater OpenAccess project.

Read more Here







 

More Articles to Read

ESP8266 Kit Released
ESP8266 Kit Released
An Arduino laser pinball machine
An Arduino laser pinball machine
CTCSS fingerprinting: A method for transmitter identification
CTCSS fingerprinting: A method for transmitter identification
TI DLP® Pico™ Technology for Aftermarket Head-up Displays
TI DLP® Pico™ Technology for Aftermarket Head-up Displays
Brute force computation for cheap log digital potentiometer
Brute force computation for cheap log digital potentiometer
Smart "Homer"
Smart "Homer"
A DIY Segway-style vehicle
A DIY Segway-style vehicle
Superbeta transistors inside: Die photos and analysis of the LM108 op amp
Superbeta transistors inside: Die photos and analysis of the LM108 op amp
Peeqo is a desktop bot that communicates through GIFs
Peeqo is a desktop bot that communicates through GIFs
Using a Programmable Input Multiplier to Minimize Integer Boundary Spurs
Using a Programmable Input Multiplier to Minimize Integer Boundary Spurs

Top


Shares