OX V1

Dependencies:   mbed

Latrix.h

Committer:
arthicha
Date:
2016-12-05
Revision:
2:84a84429750a
Parent:
1:6514e03fe62f

File content as of revision 2:84a84429750a:

#include "mbed.h"
 
 

        //Serial pc(USBTX, USBRX);
 Serial duino(PA_11,PA_12);
 
class Latrix:
{
    private: 
        
        Timer timer;
       
        
        uint8_t state_new;
        uint8_t state_menu;
        uint8_t state_show;
        uint8_t state_exit;
        uint8_t data;
        int last[3];
         
        int lis[30];
        
    public:
        void Latrix::latrix()                       //ตรงนี้นะะะะะะะะะะะะะะะะะะะะะะะะะะะะะะะะะะะะะะะะะ
        {
            for(int i=0;i<30;i++)
            {
                lis[i] = i;   
            }
            last[0] = 0;
            last[1] = 0;
            last[2] = 0;
        }
 
        void Latrix::Chackmape(){  //
            if (this->timer.read() > 1) {
            
            
                duino.putc(lis[23]);
            
                this->timer.reset();
            }
            if (duino.readable())
           {
            }
        }
 
        void Latrix::Win(){  //ชนะ
            if (this->timer.read() > 1) {
                //pc.printf("Writing!\n\r");
                duino.putc(this->lis[0]);
                duino.putc(this->lis[1]);
                duino.putc(this->lis[2]);
                this->timer.reset();
                }
            if (duino.readable())
                {
                //pc.printf("recieving %c",duino.getc());
                }
            }
 
        void  Latrix::Lose(){ //แพ้
            
            if (this->timer.read() > 1) {
                //pc.printf("Writing!\n\r");
                duino.putc(this->lis[3]);
                duino.putc(this->lis[4]);
                duino.putc(this->lis[5]);
                duino.putc(this->lis[6]);
                this->timer.reset();
                }
            if (duino.readable())
                {
                //pc.printf("recieving %c",duino.getc());
                }
         
            }    
 
 
        void Latrix::CountDown(int i){  //นับเวลา
             if (this->timer.read() > 1) {
                //pc.printf("Writing!\n\r");
                duino.putc(this->lis[16-i]);
                /*duino.putc(lis[7]);  //9  
                duino.putc(lis[8]);  //8
                duino.putc(lis[9]);  //7
                duino.putc(lis[10]);//6
                duino.putc(lis[11]);//5
                duino.putc(lis[12]);//4
                duino.putc(lis[13]);//3
                duino.putc(lis[14]);//2
                duino.putc(lis[15]);//1
                duino.putc(lis[16]);//0*/
                       
                this->timer.reset();
                }
            if (duino.readable()){
                //pc.printf("recieving %c",duino.getc());
                }
         
            }
         
         
        void Correct(){  //เช็คถูก
            if (this->timer.read() > 1) {
                //pc.printf("Writing!\n\r");
                duino.putc(lis[18]);
                this->timer.reset();
                }
            if (duino.readable()){
                //pc.printf("recieving %c",duino.getc());
                }
         
            }
            
        void Latrix::Error(){  // 
            if (this->timer.read() > 1) {
                //pc.printf("Writing!\n\r");
                duino.putc(this->lis[19]);
                this->timer.reset();
                }
            if (duino.readable()){
                //pc.printf("recieving %c",duino.getc());
                }
         
            }
        void Latrix::MapComplete(){  //ลงค่าเสร็จ
            if (this->timer.read() > 1) {
                //pc.printf("Writing!\n\r");
                
                
                duino.putc(this->lis[20]);
                
                
                this->timer.reset();
                        }
            if (duino.readable()){
                //pc.printf("recieving %c",duino.getc());
                    }         
            
            }
        void Latrix::Wbox(){  //ตัวหลัก
            if (this->timer.read() > 1) {
                //pc.printf("Writing!\n\r");
                
                
                duino.putc(this->lis[21]);
                
                
                this->timer.reset();
                        }
            if (duino.readable()){
                //pc.printf("recieving %c",duino.getc());
                    }         
            }
            
        void Latrix::RotateComplete(){  //หมุน
            if (this->timer.read() > 1) {
                //pc.printf("Writing!\n\r");
                
                
                duino.putc(this->lis[22]);
                
                
                this->timer.reset();
                        }
            if (duino.readable()){
                //pc.printf("recieving %c",duino.getc());
                    }         
            
            }
    
    
/*int main() {
    
    
    
    pc.baud(9600);
    duino.baud(9600);
    pc.printf("Starting...\n\r");
 
    timer.start();
    while (1) {
        if (btn == 9)
        {
            Win();
            
        }
        
        if (btn == 9)
        {
         Lose();
            
        }
        if (btn == 0)
        {
         number();  
            
        }
        
        if (btn == 9)  //True
        {
          correct();  
        }
        
         if (btn == 9)  //error
        {
           error(); 
            
        }
        if (btn == 9)  
        {
            heart();
        }
       
        if (btn == 9)  
        {
             woman();
        }
        if (btn == 9)  
        {
             von();
        }
        
        wait(0.4); 
        
        if(state_show == 0) {
            pc.printf("************\n");
            pc.printf(" Menu \n");
            pc.printf("1.Menu1\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("number 1-9\n");
                        
                        state_menu = 1;
                        }
                        if(pc.readable()) 
                        {
                            data = pc.getc();
                            pc.printf("\n");
                            state_menu=0;
                            switch(data) {
                                wait(0.5);
                                case '1':
                                duino.putc(lis[15]);//1
                                break;
                                
                                case '2':
                                duino.putc(lis[14]);//2
                                break;
                                case '3':
                                duino.putc(lis[13]);//3
                                break;
                                case '4':
                                duino.putc(lis[12]);//4
                                break;
                                case '5':
                                duino.putc(lis[11]);//5
                                break;
                                case '6':
                                duino.putc(lis[10]);//6
                                break;
                                case '7':
                                duino.putc(lis[9]);//7
                                break;
                                case '8':
                                duino.putc(lis[8]);//8
                                break;
                                case '9':
                                duino.putc(lis[7]);//9
                                
                                break;
                                case 'H':
                                duino.putc(lis[17]);//happy
                                
                                break;
                               
                                
                                default:
                                pc.printf("plz select a or s\n");
                                pc.printf("\n\n");
                                break;
                                }
                                }
                                } while(state_exit ==0);
                                pc.printf("\n");
                                break;
        
        
       
    }
}
}
}*/