serial test menu

Dependencies:   mbed

main.cpp

Committer:
aulvaa
Date:
2015-10-20
Revision:
1:df3b700ba2d9
Parent:
0:f4e546303b4e

File content as of revision 1:df3b700ba2d9:

#include "mbed.h"

//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut led[] = {D2,D3,D4,D5,D6,D7,D8,D9};
DigitalOut myled(LED1);
DigitalIn sw(D0);
double speed=0.1;
int pat = 1,tog=0;

int main()
{

    uint8_t state_menu=0;
    uint8_t state_show=0;
    uint8_t state_exit =0;
    uint8_t data;

    myled = 0;
    pc.printf("Hello World !\n");
    while(1) {
        if(state_show == 0) {
            pc.printf("Menu\n");
            pc.printf("1.LED Test\n");
            pc.printf("2.Print Test\n");
            state_show =1;
        }
        if(pc.readable()) {
            data = pc.getc();
            pc.printf("\n");
            state_show =0;
            state_exit =0;

            switch(data) {
                case '1':
                    do {
                        if(state_menu == 0) {
                            pc.printf("LED Test\n");
                            pc.printf("a.LED Pattern1\n");
                            pc.printf("d.LED Pattern2\n");
                        
                            pc.printf("s.Exit\n");
                            state_menu = 1;
                        }
                        if(pc.readable()) {
                            data = pc.getc();
                            pc.printf("\n");
                            state_menu=0;

                            switch(data) {

                                case 'a':
                                    if(pat==1){
                                         for(int x=0;x<=7;x++){
                                                led[x]=1;
                                                wait(speed);
                                                 led[x]=0;
                                         
                                            }
                                         }                                 
                                    break;

                                case 'd':
                                   if(pat==2){
                                        for(int x=0;x<=7;x++){
                                                 led[x]=1;
                                                 wait(speed);
                                                
                                        }   
                                                 for(int x=0;x<=7;x++){
                                                  led[x]=0;
                                                  wait(speed);
                                              
                                         }
        
                                            }
                                    break;

                                case 's':
                                    state_exit =1;
                                   
                                    break;

                                default:
                                    pc.printf("please select a or s\n");
                                    pc.printf("\n");
                                    break;

                            }
                        }



                    } while(state_exit ==0);
                    pc.printf("\n\n");
                    break;

                case '2':

                    do {
                        if(state_menu == 0) {
                            pc.printf("LED Test\n");
                            pc.printf("a.Menu 2 TEST\n");
                            pc.printf("s.Run\n");
                            pc.printf("x.Exit\n");
                            state_menu = 1;
                        }
                        if(sw.read()) {
                            data = pc.getc();
                            pc.printf("\n");
                            state_menu=0;
                            myled = 1;
                            pc.putc(1);
                            }
                            
                            else 
                            {   myled = 0;
                                pc.putc(0);
                                }
                                
                             

                                default:
                                    pc.printf("plz select a or s\n");
                                    pc.printf("\n\n");
                                    break;

                            
                        }



                    while(state_exit ==0);
                    pc.printf("\n\n");
                    break;


                case 0x00:

                    break;

                
            }
        }






    }
}