Simple program to show how keypad polling works.

Dependencies:   Skool_wkshp_lib2015 mbed

Committer:
lvagasi
Date:
Fri Oct 02 22:05:45 2015 +0000
Revision:
0:6ce746e9ad82
Simple program to show how keypad polling works.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lvagasi 0:6ce746e9ad82 1 #include "mbed.h"
lvagasi 0:6ce746e9ad82 2 #include "serial_lcd.h"
lvagasi 0:6ce746e9ad82 3 #include "pc_uart.h"
lvagasi 0:6ce746e9ad82 4 #include "keypad.h"
lvagasi 0:6ce746e9ad82 5
lvagasi 0:6ce746e9ad82 6 PwmOut speaker(PB_4); // Speaker
lvagasi 0:6ce746e9ad82 7 extern uint32_t Index;
lvagasi 0:6ce746e9ad82 8 extern uint32_t new_key;
lvagasi 0:6ce746e9ad82 9
lvagasi 0:6ce746e9ad82 10 int main()
lvagasi 0:6ce746e9ad82 11 {
lvagasi 0:6ce746e9ad82 12 int key;
lvagasi 0:6ce746e9ad82 13 int prev_key = 0;
lvagasi 0:6ce746e9ad82 14
lvagasi 0:6ce746e9ad82 15 Init_keypad();
lvagasi 0:6ce746e9ad82 16 init_ser_lcd();
lvagasi 0:6ce746e9ad82 17 write_ser_lcd(0x80, false); // set DDRAM addr to 0x00, beginning of 1st line
lvagasi 0:6ce746e9ad82 18 wait_us(30);
lvagasi 0:6ce746e9ad82 19
lvagasi 0:6ce746e9ad82 20 speaker.period((float)(1.0f/432.0f));
lvagasi 0:6ce746e9ad82 21
lvagasi 0:6ce746e9ad82 22 while (1) {
lvagasi 0:6ce746e9ad82 23
lvagasi 0:6ce746e9ad82 24 key = Poll_keypad_full();
lvagasi 0:6ce746e9ad82 25 speaker = 0.5;
lvagasi 0:6ce746e9ad82 26 wait(0.1);
lvagasi 0:6ce746e9ad82 27 speaker = 0;
lvagasi 0:6ce746e9ad82 28 write_ser_lcd((char)key,true);
lvagasi 0:6ce746e9ad82 29 if (key == '*') {
lvagasi 0:6ce746e9ad82 30 if (prev_key == '*') {
lvagasi 0:6ce746e9ad82 31 write_ser_lcd(0xC0, false);
lvagasi 0:6ce746e9ad82 32 }
lvagasi 0:6ce746e9ad82 33 }
lvagasi 0:6ce746e9ad82 34 if (key == '#') {
lvagasi 0:6ce746e9ad82 35 if (prev_key == '#') {
lvagasi 0:6ce746e9ad82 36 write_ser_lcd(0x01, false); // Clear display
lvagasi 0:6ce746e9ad82 37 wait_us(1100);
lvagasi 0:6ce746e9ad82 38 write_ser_lcd(0x06, false); // Entry mode set
lvagasi 0:6ce746e9ad82 39 wait_us(30);
lvagasi 0:6ce746e9ad82 40 write_ser_lcd(0x0C, false); // Display ON, Cursor OFF, Blink OFF
lvagasi 0:6ce746e9ad82 41 wait_us(30);
lvagasi 0:6ce746e9ad82 42 write_ser_lcd(0x80, false); // set DDRAM addr to 0x00, beginning of 1st line
lvagasi 0:6ce746e9ad82 43 wait_us(30);
lvagasi 0:6ce746e9ad82 44 }
lvagasi 0:6ce746e9ad82 45 }
lvagasi 0:6ce746e9ad82 46
lvagasi 0:6ce746e9ad82 47 prev_key = key;
lvagasi 0:6ce746e9ad82 48
lvagasi 0:6ce746e9ad82 49 }
lvagasi 0:6ce746e9ad82 50 }
lvagasi 0:6ce746e9ad82 51