MENGLU WU / Mbed 2 deprecated Lab1_Part1

Dependencies:   mbed

Part1/Polling.cpp

Committer:
menglu_wu
Date:
2015-01-29
Revision:
0:217de6e7e29a

File content as of revision 0:217de6e7e29a:

#include "mbed.h"

DigitalIn     P5(p5); //connected to 1kohms resistor and PIN5 of the keypad
DigitalIn     P6(p6); //connected to 1kohms resistor and PIN6 of the keypad
DigitalOut     P7(p7);//connected to PIN8 of the keypad
DigitalOut     P8(p8);//connected to PIN4 of the keypad
DigitalOut    Led1(LED1);
DigitalOut    Led2(LED2);

int main()
{
    //set on both PIN8 and PIN4 of the keypad to detect which button is pressed.
    P7 = 1;
    P8 = 1;
    while(1) {
        if (P5 == 1) //LED1 is on when Button "2" is pressed
            Led1 = 1;
        else if(P6 == 1)//LED2 is on when Button "#" is pressed
            Led2 = 1;
        else { //set LEDs off if no button is pressed
            Led1 = 0;
            Led2 = 0;
        }
    }
}