Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Keypad.h
- Committer:
- avinashr
- Date:
- 2015-03-26
- Revision:
- 1:4ec28912c9e7
- Child:
- 2:2cc70773996b
File content as of revision 1:4ec28912c9e7:
#include "mbed.h"
//#include "RequestQueue.h"
//selection pin
volatile int index = 1;
Serial pc(USBTX, USBRX);
//Row pins
InterruptIn inputOne(p8);
InterruptIn inputTwo(p7);
InterruptIn inputThree(p6);
InterruptIn inputFour(p5);
//Coloumn pins
DigitalOut outputOne(p9);
DigitalOut outputTwo(p10);
DigitalOut outputThree(p11);
DigitalOut outputFour(p12);
//Timer to scan
Ticker keypadTicker ;
float scanInterval = 0.004; //4ms
void changeConfiguration();
void keyOnePressed (){
keypadTicker .detach();
if (index == 1)
pc.printf(": 1 is pressed :");
if (index == 2)
pc.printf(": 4 is pressed :");
if (index ==3)
pc.printf(": 7 is pressed :");
if (index ==4)
pc.printf(": * is pressed :");
}
void keyOneReleased (){
keypadTicker .attach(&changeConfiguration,scanInterval);
}
void keyTwoPressed (){
keypadTicker .detach();
if (index == 1)
pc.printf(": 2 is pressed :");
if (index == 2)
pc.printf(": 5 is pressed :");
if (index ==3)
pc.printf(": 8 is pressed :");
if (index ==4)
pc.printf(": 0 is pressed :");
}
void keyTwoReleased (){
keypadTicker .attach(&changeConfiguration,scanInterval);
}
void keyThreePressed (){
keypadTicker .detach();
if (index == 1)
pc.printf(": 3 is pressed :");
if (index == 2)
pc.printf(": 6 is pressed :");
if (index ==3)
pc.printf(": 9 is pressed :");
if (index ==4)
pc.printf(": # is pressed :");
}
void keyThreeReleased (){
keypadTicker .attach(&changeConfiguration,scanInterval);
}
void keyFourPressed (){
keypadTicker .detach();
if (index == 1)
pc.printf(": A is pressed :");
if (index == 2)
pc.printf(": B is pressed :");
if (index ==3)
pc.printf(": c is pressed :");
if (index ==4)
pc.printf(": D is pressed :");
}
void keyFourReleased (){
keypadTicker .attach(&changeConfiguration,scanInterval);
}
void changeConfiguration(){
index =index +1;
if(index == 5)
index = 1;
switch (index )
{
case 1:
outputOne = 0;
outputTwo = 1;
outputThree = 1;
outputFour = 1;
break;
case 2:
outputOne = 1;
outputTwo = 0;
outputThree = 1;
outputFour = 1;
break;
case 3:
outputOne = 1;
outputTwo = 1;
outputThree = 0;
outputFour = 1;
break;
case 4:
outputOne = 1;
outputTwo = 1;
outputThree = 1;
outputFour = 0;
break;
default : break;
}
}
void initializeKeypad(){
outputOne = 1;
outputTwo = 1;
outputThree = 1;
outputFour = 1;
inputOne.fall(&keyOnePressed);
inputOne.rise(&keyOneReleased);
inputTwo.fall(&keyTwoPressed);
inputTwo.rise(&keyTwoReleased);
inputThree.fall(&keyThreePressed);
inputThree.rise(&keyThreeReleased);
inputFour.fall(&keyFourPressed);
inputFour.rise(&keyFourReleased);
keypadTicker.attach(&changeConfiguration, scanInterval);
}