set name

Dependencies:   mbed

Committer:
Supermil
Date:
Thu Dec 07 14:42:08 2017 +0000
Revision:
0:4e9a4a9a9fb5
input button to set name;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Supermil 0:4e9a4a9a9fb5 1 #include "mbed.h"
Supermil 0:4e9a4a9a9fb5 2
Supermil 0:4e9a4a9a9fb5 3 DigitalIn B_UP(PB_13);
Supermil 0:4e9a4a9a9fb5 4 DigitalIn B_OK(PB_14);
Supermil 0:4e9a4a9a9fb5 5 DigitalIn B_DOWN(PB_15);
Supermil 0:4e9a4a9a9fb5 6 DigitalIn B_ENTER(PB_1);
Supermil 0:4e9a4a9a9fb5 7
Supermil 0:4e9a4a9a9fb5 8 Serial pc(D1, D0);
Supermil 0:4e9a4a9a9fb5 9
Supermil 0:4e9a4a9a9fb5 10 int state,size,count_ok,mode_name;
Supermil 0:4e9a4a9a9fb5 11 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'};
Supermil 0:4e9a4a9a9fb5 12 char user_name[10];
Supermil 0:4e9a4a9a9fb5 13
Supermil 0:4e9a4a9a9fb5 14 int main() {
Supermil 0:4e9a4a9a9fb5 15 state = 0;
Supermil 0:4e9a4a9a9fb5 16 size = 0;
Supermil 0:4e9a4a9a9fb5 17 count_ok = 0;
Supermil 0:4e9a4a9a9fb5 18 mode_name = 1;
Supermil 0:4e9a4a9a9fb5 19
Supermil 0:4e9a4a9a9fb5 20 while(mode_name) {
Supermil 0:4e9a4a9a9fb5 21
Supermil 0:4e9a4a9a9fb5 22 if(B_UP == 0){
Supermil 0:4e9a4a9a9fb5 23 if(state == 0){
Supermil 0:4e9a4a9a9fb5 24 state = 25;
Supermil 0:4e9a4a9a9fb5 25 }
Supermil 0:4e9a4a9a9fb5 26 else{
Supermil 0:4e9a4a9a9fb5 27 state--;
Supermil 0:4e9a4a9a9fb5 28 }
Supermil 0:4e9a4a9a9fb5 29 wait_ms(500);
Supermil 0:4e9a4a9a9fb5 30 }
Supermil 0:4e9a4a9a9fb5 31 if(B_DOWN == 0){
Supermil 0:4e9a4a9a9fb5 32 if(state == 25){
Supermil 0:4e9a4a9a9fb5 33 state = 0;
Supermil 0:4e9a4a9a9fb5 34 }
Supermil 0:4e9a4a9a9fb5 35 else{
Supermil 0:4e9a4a9a9fb5 36 state++;
Supermil 0:4e9a4a9a9fb5 37 }
Supermil 0:4e9a4a9a9fb5 38 wait_ms(500);
Supermil 0:4e9a4a9a9fb5 39 }
Supermil 0:4e9a4a9a9fb5 40 if(B_OK == 0){
Supermil 0:4e9a4a9a9fb5 41 while(B_OK == 0){
Supermil 0:4e9a4a9a9fb5 42 count_ok++;
Supermil 0:4e9a4a9a9fb5 43 wait_ms(100);
Supermil 0:4e9a4a9a9fb5 44 }
Supermil 0:4e9a4a9a9fb5 45 if(count_ok > 10 && size > 0){
Supermil 0:4e9a4a9a9fb5 46 pc.printf("hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh");
Supermil 0:4e9a4a9a9fb5 47 pc.printf(" count_ok = %d\n",count_ok);
Supermil 0:4e9a4a9a9fb5 48 size--;
Supermil 0:4e9a4a9a9fb5 49 user_name[size] = NULL;
Supermil 0:4e9a4a9a9fb5 50
Supermil 0:4e9a4a9a9fb5 51 }
Supermil 0:4e9a4a9a9fb5 52 else if(count_ok <= 10){
Supermil 0:4e9a4a9a9fb5 53 user_name[size++] = alphabet[state];
Supermil 0:4e9a4a9a9fb5 54 }
Supermil 0:4e9a4a9a9fb5 55 count_ok = 0;
Supermil 0:4e9a4a9a9fb5 56 // wait_ms(500);
Supermil 0:4e9a4a9a9fb5 57 }
Supermil 0:4e9a4a9a9fb5 58 if(B_ENTER == 0){
Supermil 0:4e9a4a9a9fb5 59 mode_name = 0;
Supermil 0:4e9a4a9a9fb5 60 break;
Supermil 0:4e9a4a9a9fb5 61 }
Supermil 0:4e9a4a9a9fb5 62
Supermil 0:4e9a4a9a9fb5 63 pc.printf("state = %c ",alphabet[state]);
Supermil 0:4e9a4a9a9fb5 64 pc.printf(" state = %s ",user_name);
Supermil 0:4e9a4a9a9fb5 65 pc.printf(" size = %d \n",size);
Supermil 0:4e9a4a9a9fb5 66 }
Supermil 0:4e9a4a9a9fb5 67 pc.printf("Your name is : %s \n",user_name);
Supermil 0:4e9a4a9a9fb5 68 }