oki

Dependencies:   mbed

Fork of ProjetInfo2_Multi by julien bitoun

Files at this revision

API Documentation at this revision

Comitter:
thomasstrcic
Date:
Tue Jun 12 14:45:54 2018 +0000
Parent:
2:ae058dfdebac
Commit message:
fuck bitoun

Changed in this revision

TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
coffre.cpp Show annotated file Show diff for this revision Revisions of this file
coffre.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
music.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Tue Jun 12 14:45:54 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
--- a/coffre.cpp	Fri Jun 01 11:36:44 2018 +0000
+++ b/coffre.cpp	Tue Jun 12 14:45:54 2018 +0000
@@ -1,12 +1,23 @@
 #include"mbed.h"
+#include "TextLCD.h"
 
-
-BusIn digicode(p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16);
+//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 lireval(){
     int val;
     if(digicode.read()==0){
         val=-3;
@@ -46,7 +57,7 @@
         }
         return val;
 }
-
+*/
 void servo()
 {
     int c=0;
@@ -90,4 +101,175 @@
                 
         }
     }
+}
+
+
+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]);
+    }
 }
\ No newline at end of file
--- a/coffre.h	Fri Jun 01 11:36:44 2018 +0000
+++ b/coffre.h	Tue Jun 12 14:45:54 2018 +0000
@@ -2,5 +2,6 @@
 
 void servo(void);
 int lireval(void);
+void changement_code (int *);
 
 
--- a/main.cpp	Fri Jun 01 11:36:44 2018 +0000
+++ b/main.cpp	Tue Jun 12 14:45:54 2018 +0000
@@ -1,6 +1,7 @@
 #include "mbed.h"
 #include "coffre.h"
 #include "music.h"
+#include "TextLCD.h"
 
 
 #define O 0.0193
@@ -10,20 +11,24 @@
 
 // VARIABLE *****************
 
-
+extern TextLCD LCD ;
 extern BusIn digicode;
 DigitalOut led1(p20);
 DigitalOut led2(p18);
 Timer t1;
 Timer t2;
-Timer t3;
-int code[4]={2,1,0,3};
-int etat =0;
-int   N_precedent;
-int N;
+extern int u;
+extern Timer t3;
+extern int code[4];
+extern int etat =0;
+extern int   N_precedent;
+extern int N;
 int juste;
 int count;
-Serial pc (USBTX,USBRX);
+ extern Serial pc;
+extern Serial bluetooth;
+extern char chara;
+DigitalIn bp (p30);
 
 
 
@@ -33,27 +38,42 @@
 
 int main()
 {
+    bp.mode(PullUp);
     
     while(1) 
     {
         N_precedent=N;
         t3.start();
-        if(t3.read()>0.01)
+        if (bluetooth.readable())
+        {
+            chara=bluetooth.getc();
+            N=chara-'0';
+        }
+        else
         {
-            N=lireval();
-            t3.reset();
-            t3.stop();
+            N=-3;
         }
-        
+        if (N==10)
+        {
+            N=-2;
+        }        
         switch(etat)
         {
             case 0:
+            LCD.cls();
+            LCD.printf("code :");
                 if (count>=3)
                 {
                     
                     led2.write(1);
+                    LCD.cls();
+                    LCD.printf("appel");
+                    LCD.locate(0,1);
+                    LCD.printf("police");
                     music();
-                    //wait(3);
+                    
+                    wait(3);
+                    LCD.cls();
                     count=0;
                 }
                 
@@ -69,6 +89,11 @@
                     t1.start();
                     
                 }
+                if (N_precedent==-3 and bp.read()==0)
+                {
+                    changement_code(code);
+                    u=0;
+                }
                 pc.printf("etat =0\n\r");
                 break;
             case 1 : 
@@ -109,7 +134,7 @@
                     pc.printf("bravo c bon msieur\n\r");
                     juste=1;
                     
-                    //wait(0.5);
+                    wait(0.5);
                     t2.reset();
                     t2.start();
                 }
@@ -123,9 +148,9 @@
                     
             case 4:
                 
-            
+                
                 pc.printf("etat =4\n\r");
-                if(t2.read()>2)
+                if(t2.read()>0.5)
                 {
                     etat=0;
                 }
@@ -136,6 +161,9 @@
                     count++;
                     pc.printf(" count = %d \n\r",count);
                     pc.printf("c faux msieur\n\r");
+                    LCD.cls();
+            LCD.printf("code faux");
+                    //music();
                     etat=0;
                     
                 }
@@ -147,25 +175,35 @@
         switch(etat)
         {
            case 0:
-                //led1.write(1);
-                led2.write(0);
                 break;
                 
             case 1:
-                led1.write(0);
-                led2.write(0);
+                LCD.locate(0,1);
+                LCD.printf("*");
                 break;
                 
             case 2:
-                led1.write(0);
-                led2.write(0);
+                LCD.locate(1,1);
+                LCD.printf("*");
                 break;
             case 3:
+                LCD.locate(2,1);
+                LCD.printf("*");
                 break;
             case 4:
-                led1.write(0);
-                //led2.write(1);
+                LCD.cls();
+                LCD.printf("code");
+                LCD.locate(0,1);
+                LCD.printf("BON");
                 servo();
+                //wait(1);
+                LCD.cls();               
+                 break;
+            case 5:
+                LCD.cls();
+                LCD.printf("code");
+                LCD.locate(0,1);
+                LCD.printf("faux");
                 break;
             }
                 
--- a/music.h	Fri Jun 01 11:36:44 2018 +0000
+++ b/music.h	Tue Jun 12 14:45:54 2018 +0000
@@ -1,6 +1,6 @@
 // Oranges and Lemons program 
 #include "mbed.h" 
-PwmOut HP(p23); 
+PwmOut HP(p21); 
 void music (void);
 int y=0;
 float frequence[]={659,554,659,554,550,494,554,587,