nana

Dependencies:   mbed

Committer:
jujuonthebeat
Date:
Fri May 18 14:04:05 2018 +0000
Revision:
0:5755bf39c144
nana

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jujuonthebeat 0:5755bf39c144 1 #include "mbed.h"
jujuonthebeat 0:5755bf39c144 2 #include "coffre.h"
jujuonthebeat 0:5755bf39c144 3
jujuonthebeat 0:5755bf39c144 4
jujuonthebeat 0:5755bf39c144 5
jujuonthebeat 0:5755bf39c144 6
jujuonthebeat 0:5755bf39c144 7 // VARIABLE *****************
jujuonthebeat 0:5755bf39c144 8
jujuonthebeat 0:5755bf39c144 9 extern PwmOut servo;
jujuonthebeat 0:5755bf39c144 10 extern BusIn digicode;
jujuonthebeat 0:5755bf39c144 11 DigitalOut led1(p17);
jujuonthebeat 0:5755bf39c144 12 DigitalOut led2(p18);
jujuonthebeat 0:5755bf39c144 13 Timer t1;
jujuonthebeat 0:5755bf39c144 14 Timer t2;
jujuonthebeat 0:5755bf39c144 15 Timer t3;
jujuonthebeat 0:5755bf39c144 16 int code[4]={2,1,0,3};
jujuonthebeat 0:5755bf39c144 17 int etat =0;
jujuonthebeat 0:5755bf39c144 18 int N_precedent;
jujuonthebeat 0:5755bf39c144 19 int N;
jujuonthebeat 0:5755bf39c144 20 Serial pc (USBTX,USBRX);
jujuonthebeat 0:5755bf39c144 21
jujuonthebeat 0:5755bf39c144 22
jujuonthebeat 0:5755bf39c144 23
jujuonthebeat 0:5755bf39c144 24
jujuonthebeat 0:5755bf39c144 25 // CODE ************
jujuonthebeat 0:5755bf39c144 26
jujuonthebeat 0:5755bf39c144 27
jujuonthebeat 0:5755bf39c144 28 int main()
jujuonthebeat 0:5755bf39c144 29 {
jujuonthebeat 0:5755bf39c144 30 servo.period(0.02);
jujuonthebeat 0:5755bf39c144 31 while(1)
jujuonthebeat 0:5755bf39c144 32 {
jujuonthebeat 0:5755bf39c144 33 N_precedent=N;
jujuonthebeat 0:5755bf39c144 34 t3.start();
jujuonthebeat 0:5755bf39c144 35 if(t3.read()>0.1)
jujuonthebeat 0:5755bf39c144 36 {
jujuonthebeat 0:5755bf39c144 37 N=lireval();
jujuonthebeat 0:5755bf39c144 38 t3.reset();
jujuonthebeat 0:5755bf39c144 39 t3.stop();
jujuonthebeat 0:5755bf39c144 40 }
jujuonthebeat 0:5755bf39c144 41
jujuonthebeat 0:5755bf39c144 42 switch(etat)
jujuonthebeat 0:5755bf39c144 43 {
jujuonthebeat 0:5755bf39c144 44 case 0:
jujuonthebeat 0:5755bf39c144 45 fermer();
jujuonthebeat 0:5755bf39c144 46
jujuonthebeat 0:5755bf39c144 47 if ( N_precedent==-3 and N == code[0] )
jujuonthebeat 0:5755bf39c144 48 {
jujuonthebeat 0:5755bf39c144 49 etat=1;
jujuonthebeat 0:5755bf39c144 50 pc.printf("ok1\n\r");
jujuonthebeat 0:5755bf39c144 51 }
jujuonthebeat 0:5755bf39c144 52 if(N_precedent == -3 and N!=code[0] and N!=-3)
jujuonthebeat 0:5755bf39c144 53 {
jujuonthebeat 0:5755bf39c144 54 etat=5;
jujuonthebeat 0:5755bf39c144 55 t1.reset();
jujuonthebeat 0:5755bf39c144 56 t1.start();
jujuonthebeat 0:5755bf39c144 57
jujuonthebeat 0:5755bf39c144 58 }
jujuonthebeat 0:5755bf39c144 59 break;
jujuonthebeat 0:5755bf39c144 60 case 1 :
jujuonthebeat 0:5755bf39c144 61
jujuonthebeat 0:5755bf39c144 62
jujuonthebeat 0:5755bf39c144 63 if ( N_precedent==-3 and N == code[1])
jujuonthebeat 0:5755bf39c144 64 {
jujuonthebeat 0:5755bf39c144 65 etat=2;
jujuonthebeat 0:5755bf39c144 66 pc.printf("ok2\n\r");
jujuonthebeat 0:5755bf39c144 67 }
jujuonthebeat 0:5755bf39c144 68
jujuonthebeat 0:5755bf39c144 69 if(N_precedent == -3 and N!=code[1] and N!=-3)
jujuonthebeat 0:5755bf39c144 70 {
jujuonthebeat 0:5755bf39c144 71 etat=5;
jujuonthebeat 0:5755bf39c144 72 t1.reset();
jujuonthebeat 0:5755bf39c144 73 t1.start();
jujuonthebeat 0:5755bf39c144 74 }
jujuonthebeat 0:5755bf39c144 75 break;
jujuonthebeat 0:5755bf39c144 76 case 2 :
jujuonthebeat 0:5755bf39c144 77
jujuonthebeat 0:5755bf39c144 78 if( N_precedent==-3 and N == code[2])
jujuonthebeat 0:5755bf39c144 79 {
jujuonthebeat 0:5755bf39c144 80 etat=3;
jujuonthebeat 0:5755bf39c144 81 pc.printf("ok3\n\r");
jujuonthebeat 0:5755bf39c144 82 }
jujuonthebeat 0:5755bf39c144 83 if(N_precedent == -3 and N!=code[2] and N!=-3)
jujuonthebeat 0:5755bf39c144 84 {
jujuonthebeat 0:5755bf39c144 85 etat=5;
jujuonthebeat 0:5755bf39c144 86 t1.reset();
jujuonthebeat 0:5755bf39c144 87 t1.start();
jujuonthebeat 0:5755bf39c144 88 }
jujuonthebeat 0:5755bf39c144 89 break;
jujuonthebeat 0:5755bf39c144 90 case 3 :
jujuonthebeat 0:5755bf39c144 91 if ( N_precedent==-3 and N == code[3])
jujuonthebeat 0:5755bf39c144 92 {
jujuonthebeat 0:5755bf39c144 93 etat=4;
jujuonthebeat 0:5755bf39c144 94 pc.printf("bravo c bon msieur\n\r");
jujuonthebeat 0:5755bf39c144 95 ouvrir();
jujuonthebeat 0:5755bf39c144 96 wait(5);
jujuonthebeat 0:5755bf39c144 97 t2.reset();
jujuonthebeat 0:5755bf39c144 98 t2.start();
jujuonthebeat 0:5755bf39c144 99 }
jujuonthebeat 0:5755bf39c144 100 if(N_precedent == -3 and N!=code[3] and N!=-3)
jujuonthebeat 0:5755bf39c144 101 {
jujuonthebeat 0:5755bf39c144 102 etat=5;
jujuonthebeat 0:5755bf39c144 103 t1.reset();
jujuonthebeat 0:5755bf39c144 104 t1.start();
jujuonthebeat 0:5755bf39c144 105 }
jujuonthebeat 0:5755bf39c144 106 break;
jujuonthebeat 0:5755bf39c144 107
jujuonthebeat 0:5755bf39c144 108 case 4:
jujuonthebeat 0:5755bf39c144 109
jujuonthebeat 0:5755bf39c144 110
jujuonthebeat 0:5755bf39c144 111
jujuonthebeat 0:5755bf39c144 112 if(t2.read()>5)
jujuonthebeat 0:5755bf39c144 113 {
jujuonthebeat 0:5755bf39c144 114 etat=0;
jujuonthebeat 0:5755bf39c144 115 }
jujuonthebeat 0:5755bf39c144 116 break;
jujuonthebeat 0:5755bf39c144 117 case 5:
jujuonthebeat 0:5755bf39c144 118 if (t1.read()>1)
jujuonthebeat 0:5755bf39c144 119 {
jujuonthebeat 0:5755bf39c144 120 pc.printf("c faux msieur\n\r");
jujuonthebeat 0:5755bf39c144 121 etat=0;
jujuonthebeat 0:5755bf39c144 122 }
jujuonthebeat 0:5755bf39c144 123 break;
jujuonthebeat 0:5755bf39c144 124
jujuonthebeat 0:5755bf39c144 125 }
jujuonthebeat 0:5755bf39c144 126 switch(etat)
jujuonthebeat 0:5755bf39c144 127 {
jujuonthebeat 0:5755bf39c144 128 case 0:
jujuonthebeat 0:5755bf39c144 129 led1.write(1);
jujuonthebeat 0:5755bf39c144 130 led2.write(0);
jujuonthebeat 0:5755bf39c144 131 break;
jujuonthebeat 0:5755bf39c144 132
jujuonthebeat 0:5755bf39c144 133 case 1:
jujuonthebeat 0:5755bf39c144 134 led1.write(0);
jujuonthebeat 0:5755bf39c144 135 led2.write(0);
jujuonthebeat 0:5755bf39c144 136 break;
jujuonthebeat 0:5755bf39c144 137
jujuonthebeat 0:5755bf39c144 138 case 2:
jujuonthebeat 0:5755bf39c144 139 led1.write(0);
jujuonthebeat 0:5755bf39c144 140 led2.write(0);
jujuonthebeat 0:5755bf39c144 141 break;
jujuonthebeat 0:5755bf39c144 142 case 3:
jujuonthebeat 0:5755bf39c144 143 break;
jujuonthebeat 0:5755bf39c144 144 case 4:
jujuonthebeat 0:5755bf39c144 145 led1.write(0);
jujuonthebeat 0:5755bf39c144 146 led2.write(1);
jujuonthebeat 0:5755bf39c144 147 break;
jujuonthebeat 0:5755bf39c144 148 }
jujuonthebeat 0:5755bf39c144 149
jujuonthebeat 0:5755bf39c144 150
jujuonthebeat 0:5755bf39c144 151 }
jujuonthebeat 0:5755bf39c144 152 }