![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
oki
Fork of ProjetInfo2_Multi by
Diff: coffre.cpp
- Revision:
- 3:98f5de1dd010
- Parent:
- 2:ae058dfdebac
--- a/coffre.cpp Fri Jun 01 11:36:44 2018 +0000 +++ b/coffre.cpp Tue Jun 05 11:54:56 2018 +0000 @@ -1,10 +1,24 @@ #include"mbed.h" - +// ***************** VARIABLES ************************ 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); +//char chara; +//int val; +//Serial blue(p28,p27); + + +// ************* FONCTION **************** int lireval(){ int val; @@ -90,4 +104,147 @@ } } -} \ No newline at end of file +} + + +void changement_code(int *code) +{ + u=0; + while(u<1) + { + N_precedent=N; + t3.start(); + if(t3.read()>0.1) + { + N=lireval(); + t3.reset(); + t3.stop(); + } + + 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: + + if(N_precedent == -3 and N== *code) + { + 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)) + { + 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)) + { + 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)) + { + 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"); + if (N_precedent ==-3 and N!=-3) + { + a=N; + *code=a; + etat2=6; + } + pc.printf("etat 5 \n\r"); + break; + case 6: + if (N_precedent ==-3 and N!=-3) + { + b=N; + *(code+1)=b; + etat2=7; + } + pc.printf("etat 6 \n\r"); + break; + case 7: + if (N_precedent ==-3 and N!=-3) + { + c=N; + *(code+2)=c; + etat2=8; + } + pc.printf("etat 7 \n\r"); + break; + case 8: + if (N_precedent ==-3 and N!=-3) + { + d=N; + *(code+3)=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); + wait(3); + u++; + etat2=1; + break; + case 10: + pc.printf( "code errone \n\r"); + wait(00.5); + etat2=1; + break; + + } + } + for (i=0;i<4;i++) + { + pc.printf("%d \n\r",code[i]); + } +} + +/* +int bluetooth() +{ + if ( blue.readable()) + { + chara=blue.getc(); + val=chara-'0'; + } + return val; +}*/