oki

Dependencies:   mbed

Fork of ProjetInfo2_Multi by julien bitoun

Committer:
thomasstrcic
Date:
Tue May 22 11:51:24 2018 +0000
Revision:
1:d446f0124474
Parent:
0:5755bf39c144
Child:
2:ae058dfdebac
robot stcric bitoun

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