MENGLU WU / Mbed 2 deprecated Lab1_Part1

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Polling.cpp Source File

Polling.cpp

00001 #include "mbed.h"
00002 
00003 DigitalIn     P5(p5); //connected to 1kohms resistor and PIN5 of the keypad
00004 DigitalIn     P6(p6); //connected to 1kohms resistor and PIN6 of the keypad
00005 DigitalOut     P7(p7);//connected to PIN8 of the keypad
00006 DigitalOut     P8(p8);//connected to PIN4 of the keypad
00007 DigitalOut    Led1(LED1);
00008 DigitalOut    Led2(LED2);
00009 
00010 int main()
00011 {
00012     //set on both PIN8 and PIN4 of the keypad to detect which button is pressed.
00013     P7 = 1;
00014     P8 = 1;
00015     while(1) {
00016         if (P5 == 1) //LED1 is on when Button "2" is pressed
00017             Led1 = 1;
00018         else if(P6 == 1)//LED2 is on when Button "#" is pressed
00019             Led2 = 1;
00020         else { //set LEDs off if no button is pressed
00021             Led1 = 0;
00022             Led2 = 0;
00023         }
00024     }
00025 }
00026