Bluetooth

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 Serial pc(D8,D2);
00004 //Serial pc(D1,D0);
00005 
00006 AnalogIn analog_value(A1);
00007 BusOut mySegment(D9, D10, D11, D12);
00008 
00009 float meas_r; 
00010 float meas_mv;         
00011 float meas_v;
00012 
00013 int main(){
00014     
00015     uint8_t mode;
00016     uint8_t dataIn;
00017     uint8_t state_show=0;
00018     uint8_t guide=0;
00019     uint8_t mode_exit = 0;
00020     
00021     while(1){
00022         if(state_show == 0) {
00023             pc.printf("#############\n");
00024             pc.printf("     Menu   \n");
00025             pc.printf("#############\n");
00026             pc.printf("1.Segment show input number\n");
00027             pc.printf("2.Monitor input voltage\n");
00028             state_show =1;
00029         }
00030         if(pc.readable()) {
00031             mode = pc.getc();
00032             pc.printf("\n");
00033             state_show=0;
00034             mode_exit = 0;
00035             guide = 0;
00036             switch(mode) {
00037                 
00038                 case '1':    //Segment show input number
00039                     do{
00040                         
00041                         if(guide == 0){
00042                             pc.printf("##########################\n");
00043                             pc.printf("Segment show input number\n");
00044                             pc.printf("##########################\n");
00045                             pc.printf("Please key any number\n"); 
00046                             pc.printf("key x to exit\n"); 
00047                             guide = 1;
00048                         }
00049                         if(pc.readable()) {
00050                             dataIn = pc.getc();
00051                             if(dataIn == 'x'){
00052                                 pc.printf("\n");
00053                                 mode_exit = 1;
00054                             }
00055                             else{
00056                                 mySegment = dataIn;
00057                                 pc.printf("number = %c \n\n",(char)dataIn);
00058                                 guide = 0;
00059                             }
00060                         }
00061                         
00062                     }while(mode_exit ==0);
00063                     break;
00064                     
00065                 case '2':      //Monitor input voltage
00066                     do{
00067                         if(pc.readable()) {
00068                             dataIn = pc.getc();
00069                             if(dataIn == 'x'){
00070                                 mode_exit = 1;
00071                             }
00072                         }
00073                         meas_r = analog_value.read(); 
00074                         meas_mv = meas_r * 3300;         
00075                         meas_v = (float)meas_mv / 1000;
00076                         pc.printf("Input voltage = %.2f V.       key x to exit\n",meas_v); 
00077                         
00078                     }while(mode_exit ==0);
00079                     break;
00080                     
00081                 default:
00082                     pc.printf("plz select 1 or 2 only\n");
00083                     pc.printf("\n");
00084                     break;
00085                     
00086                 
00087             }
00088         }
00089     }
00090 
00091 }