set name
Dependencies: mbed
Revision 0:4e9a4a9a9fb5, committed 2017-12-07
- Comitter:
- Supermil
- Date:
- Thu Dec 07 14:42:08 2017 +0000
- Commit message:
- input button to set name;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Dec 07 14:42:08 2017 +0000 @@ -0,0 +1,68 @@ +#include "mbed.h" + +DigitalIn B_UP(PB_13); +DigitalIn B_OK(PB_14); +DigitalIn B_DOWN(PB_15); +DigitalIn B_ENTER(PB_1); + +Serial pc(D1, D0); + +int state,size,count_ok,mode_name; +char alphabet [26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; +char user_name[10]; + +int main() { + state = 0; + size = 0; + count_ok = 0; + mode_name = 1; + + while(mode_name) { + + if(B_UP == 0){ + if(state == 0){ + state = 25; + } + else{ + state--; + } + wait_ms(500); + } + if(B_DOWN == 0){ + if(state == 25){ + state = 0; + } + else{ + state++; + } + wait_ms(500); + } + if(B_OK == 0){ + while(B_OK == 0){ + count_ok++; + wait_ms(100); + } + if(count_ok > 10 && size > 0){ + pc.printf("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh"); + pc.printf(" count_ok = %d\n",count_ok); + size--; + user_name[size] = NULL; + + } + else if(count_ok <= 10){ + user_name[size++] = alphabet[state]; + } + count_ok = 0; +// wait_ms(500); + } + if(B_ENTER == 0){ + mode_name = 0; + break; + } + + pc.printf("state = %c ",alphabet[state]); + pc.printf(" state = %s ",user_name); + pc.printf(" size = %d \n",size); + } + pc.printf("Your name is : %s \n",user_name); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Dec 07 14:42:08 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e7ca05fa8600 \ No newline at end of file