set name

Dependencies:   mbed

main.cpp

Committer:
Supermil
Date:
2017-12-07
Revision:
0:4e9a4a9a9fb5

File content as of revision 0:4e9a4a9a9fb5:

#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);
}