oki

Dependencies:   mbed

Fork of ProjetInfo2_Multi by julien bitoun

coffre.cpp

Committer:
thomasstrcic
Date:
2018-06-12
Revision:
4:23e955d622f9
Parent:
2:ae058dfdebac

File content as of revision 4:23e955d622f9:

#include"mbed.h"
#include "TextLCD.h"

//BusIn digicode(p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16);
DigitalOut s(p17);
Timer t;
Timer t11;
int u;
int   N_precedent;
int N,i;
int a,b,c,d;
int code[4]={2,1,0,3};
Timer t3;
int etat2=1;
Serial pc (USBTX,USBRX);
Serial bluetooth(p28,p27);
char chara;
TextLCD LCD (p10,p11,p12,p13,p14,p15);

/*int lireval(){
    int val;
    if(digicode.read()==0){
        val=-3;
        }
    if(digicode.read()==2){
        val=7;
        }
    if(digicode.read()==4){
        val=4;
        }
    if(digicode.read()==8){
        val=1;
        }
    if(digicode.read()==16){
        val=0;
        }
    if(digicode.read()==32){
        val=8;
        }
    if(digicode.read()==64){
        val=5;
        }
    if(digicode.read()==128){
        val=2;
        }
    if(digicode.read()==256){
        val=-2;
        }
    if(digicode.read()==512){
        val=9;
        }
    if(digicode.read()==1024){
        val=6;
        }
    if(digicode.read()==2048){
        val=3;
        }
        return val;
}
*/
void servo()
{
    int c=0;
    t.start();
    t11.start();
    {
        while(c<1)
        {
            if (t11.read()>8)
            {
                t11.reset();
                c++;
            }
            if (t11.read()<4)
            {
                if(t.read()>0.02)
                { t.reset();}
                if (t.read()<0.0193)
                {
                    s.write(1);
                }
                else
                {
                    s.write(0);
                }
            }
            else
            {
                if(t.read()>0.02)
                { t.reset();}
                if (t.read()< 0.0175)
                {
                    s.write(1);
                }
                else
                {
                    s.write(0);
                }
            }
            
                
        }
    }
}


void changement_code(int *code)
{
    u=0;
    while(u<1) 
    {
        N_precedent=N;
        t3.start();
        if (bluetooth.readable())
        {
            chara=bluetooth.getc();
            N=chara-'0';
        }
        else
        {
            N=-3;
        }
        
        switch(etat2)
        {
            case 0:
             
                if ( N_precedent==-3 and N == -2 )
                {
                    pc.printf("changement de mdp : \r\n");
                    
                    etat2=1;
                }
                pc.printf("etat 0 \n\r");
                break;
            case 1:
                LCD.cls();
                    LCD.printf("ancien");
                    LCD.locate(0,1);
                    LCD.printf("code :");
            
                if(N_precedent == -3 and N== *code)
                {
                    LCD.cls();
                LCD.locate(0,0);
                LCD.printf("*");
                    etat2=2;
                    
                }
                if(N_precedent == -3 and N!=*code and N!=-3) 
                {
                    etat2=10;    
                }
                pc.printf("etat 1 \n\r");
                break;
            case 2:
                
                if(N_precedent == -3 and N==*(code+1))
                {
                    LCD.locate(1,0);
                    LCD.printf("*");
                    etat2=3;
                }
                if(N_precedent == -3 and N!=*(code+1) and N!=-3) 
                {
                    etat2=10;    
                }
                pc.printf("etat 2 \n\r");
                break;
            case 3:
                if(N_precedent == -3 and N==*(code+2))
                {
                    LCD.locate(2,0);
                    LCD.printf("*");
                    etat2=4;
                }
                if(N_precedent == -3 and N!=*(code+2) and N!=-3) 
                {
                    etat2=10;    
                }
                pc.printf("etat 3 \n\r");
                break;
            case 4:
                if(N_precedent == -3 and N==*(code+3))
                {
                    LCD.locate(3,0);
                    LCD.printf("*");
                    etat2=5;
                }
                if(N_precedent == -3 and N!=*(code+3) and N!=-3) 
                {
                    etat2=10;    
                }
                pc.printf("etat 4 \n\r");
                break;
            case 5:
                pc.printf("taper le nouveau code \n\r");
                LCD.cls();
                LCD.printf("NEW");
                LCD.locate(0,1);
                LCD.printf("CODE");
                if (N_precedent ==-3 and N!=-3)
                {
                    a=N;
                    *code=a;
                    LCD.cls();
                    LCD.printf("%d",a);
                    etat2=6;
                }
                pc.printf("etat 5 \n\r");
                break;
            case 6:
                if (N_precedent ==-3 and N!=-3)
                {
                    b=N;
                    *(code+1)=b;
                    LCD.locate(1,0);
                    LCD.printf("%d",b);
                    etat2=7;
                }
                pc.printf("etat 6 \n\r");
                break;
            case 7:
                if (N_precedent ==-3 and N!=-3)
                {
                    c=N;
                    *(code+2)=c;
                    LCD.locate(2,0);
                    LCD.printf("%d",c);
                    etat2=8;
                }
                pc.printf("etat 7 \n\r");
                break;
            case 8:
                if (N_precedent ==-3 and N!=-3)
                {
                    d=N;
                    *(code+3)=d;
                    LCD.locate(3,0);
                    LCD.printf("%d",d);
                    etat2=9;
                }
                pc.printf("etat 8 \n\r");
                break;
            case 9:
            
                pc.printf("%d \n\r",a);
                pc.printf("%d \n\r",b);
                pc.printf("%d \n\r",c);
                pc.printf("%d \n\r",d);
                LCD.cls();
                LCD.printf("code");
                LCD.locate(0,1);
                LCD.printf("change");
                wait(1);
                u++;
                etat2=1;
                break;
            case 10:
                pc.printf( "code errone \n\r");
                LCD.cls();
                LCD.printf("code");
                LCD.locate(0,1);
                LCD.printf("faux");
                wait(00.5);
                etat2=1;
                break;
            
        }
    }
    for (i=0;i<4;i++)
    {
        pc.printf("%d \n\r",code[i]);
    }
}