nana

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jujuonthebeat
Date:
Fri May 18 14:04:05 2018 +0000
Commit message:
nana

Changed in this revision

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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 5755bf39c144 coffre.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/coffre.cpp	Fri May 18 14:04:05 2018 +0000
@@ -0,0 +1,59 @@
+#include"mbed.h"
+
+
+
+PwmOut servo (p21);
+BusIn digicode(p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16);
+
+
+void fermer()
+{
+    servo.pulsewidth(0.194);
+}
+
+void ouvrir()
+{
+    
+    servo.pulsewidth(0.178);
+}
+
+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;
+}
\ No newline at end of file
diff -r 000000000000 -r 5755bf39c144 coffre.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/coffre.h	Fri May 18 14:04:05 2018 +0000
@@ -0,0 +1,7 @@
+#include "mbed.h"
+
+void fermer (void);
+void ouvrir(void);
+int lireval(void);
+
+
diff -r 000000000000 -r 5755bf39c144 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri May 18 14:04:05 2018 +0000
@@ -0,0 +1,152 @@
+#include "mbed.h"
+#include "coffre.h"
+
+
+
+
+// VARIABLE *****************
+
+extern PwmOut servo;
+extern BusIn digicode;
+DigitalOut led1(p17);
+DigitalOut led2(p18);
+Timer t1;
+Timer t2;
+Timer t3;
+int code[4]={2,1,0,3};
+int etat =0;
+int   N_precedent;
+int N; 
+Serial pc (USBTX,USBRX);
+
+
+
+
+// CODE ************
+
+
+int main()
+{
+    servo.period(0.02);
+    while(1) 
+    {
+        N_precedent=N;
+        t3.start();
+        if(t3.read()>0.1)
+        {
+            N=lireval();
+            t3.reset();
+            t3.stop();
+        }
+        
+        switch(etat)
+        {
+            case 0:
+                fermer();
+                
+                if ( N_precedent==-3 and N == code[0] ) 
+                {
+                    etat=1;
+                    pc.printf("ok1\n\r");
+                }
+                if(N_precedent == -3 and N!=code[0] and N!=-3) 
+                {
+                    etat=5;
+                    t1.reset();
+                    t1.start();
+                    
+                }
+                break;
+            case 1 : 
+                
+                
+                if ( N_precedent==-3 and N == code[1])
+                {
+                    etat=2;
+                    pc.printf("ok2\n\r");
+                }
+                
+                if(N_precedent == -3 and N!=code[1] and N!=-3)
+                {
+                    etat=5;
+                    t1.reset();
+                    t1.start();
+                }
+                break;
+            case 2 :  
+                
+                if( N_precedent==-3 and N == code[2])
+                {
+                    etat=3;
+                    pc.printf("ok3\n\r");
+                }
+                if(N_precedent == -3 and N!=code[2] and N!=-3)
+                {
+                    etat=5;
+                    t1.reset();
+                    t1.start();
+                }
+                break;
+            case 3 : 
+                if ( N_precedent==-3 and N == code[3])
+                {
+                    etat=4;
+                    pc.printf("bravo c bon msieur\n\r");
+                    ouvrir();
+                    wait(5);
+                    t2.reset();
+                    t2.start();
+                }
+                if(N_precedent == -3 and N!=code[3] and N!=-3)
+                {
+                    etat=5;
+                    t1.reset();
+                    t1.start();
+                }
+                break;
+                    
+            case 4:
+                
+            
+          
+                if(t2.read()>5)
+                {
+                    etat=0;
+                }
+                break;
+            case 5:
+                if (t1.read()>1)
+                {
+                    pc.printf("c faux msieur\n\r");
+                    etat=0;
+                }
+                break;
+            
+            }
+        switch(etat)
+        {
+           case 0:
+                led1.write(1);
+                led2.write(0);
+                break;
+                
+            case 1:
+                led1.write(0);
+                led2.write(0);
+                break;
+                
+            case 2:
+                led1.write(0);
+                led2.write(0);
+                break;
+            case 3:
+                break;
+            case 4:
+                led1.write(0);
+                led2.write(1);
+                break;
+            }
+                
+            
+        }
+    }
diff -r 000000000000 -r 5755bf39c144 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri May 18 14:04:05 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/5aab5a7997ee
\ No newline at end of file