Code for the keypad
Dependencies: TextLCD keypad mbed-rtos mbed
Revision 0:f39f0de7c0ce, committed 2017-05-08
- Comitter:
- michiel975
- Date:
- Mon May 08 19:57:56 2017 +0000
- Commit message:
- Keypad 5
Changed in this revision
diff -r 000000000000 -r f39f0de7c0ce TextLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Mon May 08 19:57:56 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
diff -r 000000000000 -r f39f0de7c0ce buzzer/buzzer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/buzzer/buzzer.cpp Mon May 08 19:57:56 2017 +0000 @@ -0,0 +1,17 @@ +#include "buzzer.h" +#include "mbed.h" + +Buzzer::Buzzer(PinName buzzerPin) : out(buzzerPin){ + out = 0.0; +} + +void Buzzer::startupBeep(){ + +} + +void Buzzer::playNote(float frequency, float duration, float volume){ + out.period(1.0/frequency); + out = volume/2.0; + wait_ms(duration); + out = 0.0; +} \ No newline at end of file
diff -r 000000000000 -r f39f0de7c0ce buzzer/buzzer.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/buzzer/buzzer.h Mon May 08 19:57:56 2017 +0000 @@ -0,0 +1,17 @@ +#ifndef BUZZER_H +#define BUZZER_H + +#include "mbed.h" + +class Buzzer{ + + public: + Buzzer(PinName buzzerPin); + void playNote(float frequency, float duration = 100, float volume = 1.0); + void startupBeep(); + + private: + PwmOut out; +}; + +#endif \ No newline at end of file
diff -r 000000000000 -r f39f0de7c0ce keypad.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/keypad.lib Mon May 08 19:57:56 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/yoonghm/code/keypad/#da060f8c03e8
diff -r 000000000000 -r f39f0de7c0ce main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon May 08 19:57:56 2017 +0000 @@ -0,0 +1,74 @@ +#include "mbed.h" +#include "rtos.h" +#include "Keypad.h" +#include "TextLCD.h" +#include "buzzer.h" + +Serial PC(USBTX, USBRX); +TextLCD * lcd; +Buzzer * buzzer; +RtosTimer *LedTimer; +DigitalOut Led1(LED1); +DigitalOut Led2(LED2); + +// Define your own keypad values +char Keytable[] = { '1', '2', '3', // r0 + '4', '5', '6', // r1 + '7', '8', '9', // r2 + '*', '0', '#', // r3 + }; + +int32_t Index = -1; +int State; + +uint32_t cbAfterInput(uint32_t _index) +{ + Index = _index; + return 0; +} + +void Blink(void const *arg) { + if (State == 1) { + Led1 = 1; + Led2 = 0; + State = 2; + } + else if (State == 2) { + LedTimer->stop(); + Led1 = 0; + Led2 = 1; + LedTimer->start(2000); // longer timer alarm + State = 1; + } +} + +int main() +{ + lcd = new TextLCD( PTC5, PTC7, PTC0, PTC9, PTC8, PTC1, TextLCD::LCD20x4 ); + lcd->printf("I am Demo Keypad\r\n"); + State = 1; + LedTimer = new RtosTimer(&Blink, osTimerPeriodic, NULL); + LedTimer->start(500); // short timer alarm + + buzzer = new Buzzer(PTA2); + buzzer->startupBeep(); + + // r0 r1 r2 r3 c0 c1 c2 c3 + //Keypad keypad(p21, p22, p23, p24, p25, p28, p27, NC); + Keypad keypad(PTC4, PTB23, PTC2, PTE26, PTB20, PTB2, PTC3, NC); + + keypad.attach(&cbAfterInput); + keypad.start(); // energize the columns c0-c3 of the keypad + + while (1) { + __wfi(); + if (Index > -1) { + lcd->cls(); + lcd->locate(0, 0); + lcd->printf("Interrupted"); + lcd->locate(0, 1); + lcd->printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]); + Index = -1; + } + } +} \ No newline at end of file
diff -r 000000000000 -r f39f0de7c0ce mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Mon May 08 19:57:56 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
diff -r 000000000000 -r f39f0de7c0ce mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon May 08 19:57:56 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/794e51388b66 \ No newline at end of file