oki

Dependencies:   mbed

Fork of ProjetInfo2_Multi by julien bitoun

Committer:
thomasstrcic
Date:
Tue Jun 05 11:54:56 2018 +0000
Revision:
3:98f5de1dd010
Parent:
2:ae058dfdebac
nique bitoun

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jujuonthebeat 0:5755bf39c144 1 #include"mbed.h"
jujuonthebeat 0:5755bf39c144 2
thomasstrcic 3:98f5de1dd010 3 // ***************** VARIABLES ************************
jujuonthebeat 0:5755bf39c144 4 BusIn digicode(p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16);
thomasstrcic 2:ae058dfdebac 5 DigitalOut s(p17);
thomasstrcic 2:ae058dfdebac 6 Timer t;
thomasstrcic 2:ae058dfdebac 7 Timer t11;
thomasstrcic 3:98f5de1dd010 8 int u;
thomasstrcic 3:98f5de1dd010 9 int N_precedent;
thomasstrcic 3:98f5de1dd010 10 int N,i;
thomasstrcic 3:98f5de1dd010 11 int a,b,c,d;
thomasstrcic 3:98f5de1dd010 12 int code[4]={2,1,0,3};
thomasstrcic 3:98f5de1dd010 13 Timer t3;
thomasstrcic 3:98f5de1dd010 14 int etat2=1;
thomasstrcic 3:98f5de1dd010 15 Serial pc (USBTX,USBRX);
thomasstrcic 3:98f5de1dd010 16 //char chara;
thomasstrcic 3:98f5de1dd010 17 //int val;
thomasstrcic 3:98f5de1dd010 18 //Serial blue(p28,p27);
thomasstrcic 3:98f5de1dd010 19
thomasstrcic 3:98f5de1dd010 20
thomasstrcic 3:98f5de1dd010 21 // ************* FONCTION ****************
jujuonthebeat 0:5755bf39c144 22
jujuonthebeat 0:5755bf39c144 23 int lireval(){
jujuonthebeat 0:5755bf39c144 24 int val;
jujuonthebeat 0:5755bf39c144 25 if(digicode.read()==0){
jujuonthebeat 0:5755bf39c144 26 val=-3;
jujuonthebeat 0:5755bf39c144 27 }
jujuonthebeat 0:5755bf39c144 28 if(digicode.read()==2){
jujuonthebeat 0:5755bf39c144 29 val=7;
jujuonthebeat 0:5755bf39c144 30 }
jujuonthebeat 0:5755bf39c144 31 if(digicode.read()==4){
jujuonthebeat 0:5755bf39c144 32 val=4;
jujuonthebeat 0:5755bf39c144 33 }
jujuonthebeat 0:5755bf39c144 34 if(digicode.read()==8){
jujuonthebeat 0:5755bf39c144 35 val=1;
jujuonthebeat 0:5755bf39c144 36 }
jujuonthebeat 0:5755bf39c144 37 if(digicode.read()==16){
jujuonthebeat 0:5755bf39c144 38 val=0;
jujuonthebeat 0:5755bf39c144 39 }
jujuonthebeat 0:5755bf39c144 40 if(digicode.read()==32){
jujuonthebeat 0:5755bf39c144 41 val=8;
jujuonthebeat 0:5755bf39c144 42 }
jujuonthebeat 0:5755bf39c144 43 if(digicode.read()==64){
jujuonthebeat 0:5755bf39c144 44 val=5;
jujuonthebeat 0:5755bf39c144 45 }
jujuonthebeat 0:5755bf39c144 46 if(digicode.read()==128){
jujuonthebeat 0:5755bf39c144 47 val=2;
jujuonthebeat 0:5755bf39c144 48 }
jujuonthebeat 0:5755bf39c144 49 if(digicode.read()==256){
jujuonthebeat 0:5755bf39c144 50 val=-2;
jujuonthebeat 0:5755bf39c144 51 }
jujuonthebeat 0:5755bf39c144 52 if(digicode.read()==512){
jujuonthebeat 0:5755bf39c144 53 val=9;
jujuonthebeat 0:5755bf39c144 54 }
jujuonthebeat 0:5755bf39c144 55 if(digicode.read()==1024){
jujuonthebeat 0:5755bf39c144 56 val=6;
jujuonthebeat 0:5755bf39c144 57 }
jujuonthebeat 0:5755bf39c144 58 if(digicode.read()==2048){
jujuonthebeat 0:5755bf39c144 59 val=3;
jujuonthebeat 0:5755bf39c144 60 }
jujuonthebeat 0:5755bf39c144 61 return val;
thomasstrcic 2:ae058dfdebac 62 }
thomasstrcic 2:ae058dfdebac 63
thomasstrcic 2:ae058dfdebac 64 void servo()
thomasstrcic 2:ae058dfdebac 65 {
thomasstrcic 2:ae058dfdebac 66 int c=0;
thomasstrcic 2:ae058dfdebac 67 t.start();
thomasstrcic 2:ae058dfdebac 68 t11.start();
thomasstrcic 2:ae058dfdebac 69 {
thomasstrcic 2:ae058dfdebac 70 while(c<1)
thomasstrcic 2:ae058dfdebac 71 {
thomasstrcic 2:ae058dfdebac 72 if (t11.read()>8)
thomasstrcic 2:ae058dfdebac 73 {
thomasstrcic 2:ae058dfdebac 74 t11.reset();
thomasstrcic 2:ae058dfdebac 75 c++;
thomasstrcic 2:ae058dfdebac 76 }
thomasstrcic 2:ae058dfdebac 77 if (t11.read()<4)
thomasstrcic 2:ae058dfdebac 78 {
thomasstrcic 2:ae058dfdebac 79 if(t.read()>0.02)
thomasstrcic 2:ae058dfdebac 80 { t.reset();}
thomasstrcic 2:ae058dfdebac 81 if (t.read()<0.0193)
thomasstrcic 2:ae058dfdebac 82 {
thomasstrcic 2:ae058dfdebac 83 s.write(1);
thomasstrcic 2:ae058dfdebac 84 }
thomasstrcic 2:ae058dfdebac 85 else
thomasstrcic 2:ae058dfdebac 86 {
thomasstrcic 2:ae058dfdebac 87 s.write(0);
thomasstrcic 2:ae058dfdebac 88 }
thomasstrcic 2:ae058dfdebac 89 }
thomasstrcic 2:ae058dfdebac 90 else
thomasstrcic 2:ae058dfdebac 91 {
thomasstrcic 2:ae058dfdebac 92 if(t.read()>0.02)
thomasstrcic 2:ae058dfdebac 93 { t.reset();}
thomasstrcic 2:ae058dfdebac 94 if (t.read()< 0.0175)
thomasstrcic 2:ae058dfdebac 95 {
thomasstrcic 2:ae058dfdebac 96 s.write(1);
thomasstrcic 2:ae058dfdebac 97 }
thomasstrcic 2:ae058dfdebac 98 else
thomasstrcic 2:ae058dfdebac 99 {
thomasstrcic 2:ae058dfdebac 100 s.write(0);
thomasstrcic 2:ae058dfdebac 101 }
thomasstrcic 2:ae058dfdebac 102 }
thomasstrcic 2:ae058dfdebac 103
thomasstrcic 2:ae058dfdebac 104
thomasstrcic 2:ae058dfdebac 105 }
thomasstrcic 2:ae058dfdebac 106 }
thomasstrcic 3:98f5de1dd010 107 }
thomasstrcic 3:98f5de1dd010 108
thomasstrcic 3:98f5de1dd010 109
thomasstrcic 3:98f5de1dd010 110 void changement_code(int *code)
thomasstrcic 3:98f5de1dd010 111 {
thomasstrcic 3:98f5de1dd010 112 u=0;
thomasstrcic 3:98f5de1dd010 113 while(u<1)
thomasstrcic 3:98f5de1dd010 114 {
thomasstrcic 3:98f5de1dd010 115 N_precedent=N;
thomasstrcic 3:98f5de1dd010 116 t3.start();
thomasstrcic 3:98f5de1dd010 117 if(t3.read()>0.1)
thomasstrcic 3:98f5de1dd010 118 {
thomasstrcic 3:98f5de1dd010 119 N=lireval();
thomasstrcic 3:98f5de1dd010 120 t3.reset();
thomasstrcic 3:98f5de1dd010 121 t3.stop();
thomasstrcic 3:98f5de1dd010 122 }
thomasstrcic 3:98f5de1dd010 123
thomasstrcic 3:98f5de1dd010 124 switch(etat2)
thomasstrcic 3:98f5de1dd010 125 {
thomasstrcic 3:98f5de1dd010 126 case 0:
thomasstrcic 3:98f5de1dd010 127
thomasstrcic 3:98f5de1dd010 128 if ( N_precedent==-3 and N == -2 )
thomasstrcic 3:98f5de1dd010 129 {
thomasstrcic 3:98f5de1dd010 130 pc.printf("changement de mdp : \r\n");
thomasstrcic 3:98f5de1dd010 131 etat2=1;
thomasstrcic 3:98f5de1dd010 132 }
thomasstrcic 3:98f5de1dd010 133 pc.printf("etat 0 \n\r");
thomasstrcic 3:98f5de1dd010 134 break;
thomasstrcic 3:98f5de1dd010 135 case 1:
thomasstrcic 3:98f5de1dd010 136
thomasstrcic 3:98f5de1dd010 137 if(N_precedent == -3 and N== *code)
thomasstrcic 3:98f5de1dd010 138 {
thomasstrcic 3:98f5de1dd010 139 etat2=2;
thomasstrcic 3:98f5de1dd010 140 }
thomasstrcic 3:98f5de1dd010 141 if(N_precedent == -3 and N!=*code and N!=-3)
thomasstrcic 3:98f5de1dd010 142 {
thomasstrcic 3:98f5de1dd010 143 etat2=10;
thomasstrcic 3:98f5de1dd010 144 }
thomasstrcic 3:98f5de1dd010 145 pc.printf("etat 1 \n\r");
thomasstrcic 3:98f5de1dd010 146 break;
thomasstrcic 3:98f5de1dd010 147 case 2:
thomasstrcic 3:98f5de1dd010 148 if(N_precedent == -3 and N==*(code+1))
thomasstrcic 3:98f5de1dd010 149 {
thomasstrcic 3:98f5de1dd010 150 etat2=3;
thomasstrcic 3:98f5de1dd010 151 }
thomasstrcic 3:98f5de1dd010 152 if(N_precedent == -3 and N!=*(code+1) and N!=-3)
thomasstrcic 3:98f5de1dd010 153 {
thomasstrcic 3:98f5de1dd010 154 etat2=10;
thomasstrcic 3:98f5de1dd010 155 }
thomasstrcic 3:98f5de1dd010 156 pc.printf("etat 2 \n\r");
thomasstrcic 3:98f5de1dd010 157 break;
thomasstrcic 3:98f5de1dd010 158 case 3:
thomasstrcic 3:98f5de1dd010 159 if(N_precedent == -3 and N==*(code+2))
thomasstrcic 3:98f5de1dd010 160 {
thomasstrcic 3:98f5de1dd010 161 etat2=4;
thomasstrcic 3:98f5de1dd010 162 }
thomasstrcic 3:98f5de1dd010 163 if(N_precedent == -3 and N!=*(code+2) and N!=-3)
thomasstrcic 3:98f5de1dd010 164 {
thomasstrcic 3:98f5de1dd010 165 etat2=10;
thomasstrcic 3:98f5de1dd010 166 }
thomasstrcic 3:98f5de1dd010 167 pc.printf("etat 3 \n\r");
thomasstrcic 3:98f5de1dd010 168 break;
thomasstrcic 3:98f5de1dd010 169 case 4:
thomasstrcic 3:98f5de1dd010 170 if(N_precedent == -3 and N==*(code+3))
thomasstrcic 3:98f5de1dd010 171 {
thomasstrcic 3:98f5de1dd010 172 etat2=5;
thomasstrcic 3:98f5de1dd010 173 }
thomasstrcic 3:98f5de1dd010 174 if(N_precedent == -3 and N!=*(code+3) and N!=-3)
thomasstrcic 3:98f5de1dd010 175 {
thomasstrcic 3:98f5de1dd010 176 etat2=10;
thomasstrcic 3:98f5de1dd010 177 }
thomasstrcic 3:98f5de1dd010 178 pc.printf("etat 4 \n\r");
thomasstrcic 3:98f5de1dd010 179 break;
thomasstrcic 3:98f5de1dd010 180 case 5:
thomasstrcic 3:98f5de1dd010 181 pc.printf("taper le nouveau code \n\r");
thomasstrcic 3:98f5de1dd010 182 if (N_precedent ==-3 and N!=-3)
thomasstrcic 3:98f5de1dd010 183 {
thomasstrcic 3:98f5de1dd010 184 a=N;
thomasstrcic 3:98f5de1dd010 185 *code=a;
thomasstrcic 3:98f5de1dd010 186 etat2=6;
thomasstrcic 3:98f5de1dd010 187 }
thomasstrcic 3:98f5de1dd010 188 pc.printf("etat 5 \n\r");
thomasstrcic 3:98f5de1dd010 189 break;
thomasstrcic 3:98f5de1dd010 190 case 6:
thomasstrcic 3:98f5de1dd010 191 if (N_precedent ==-3 and N!=-3)
thomasstrcic 3:98f5de1dd010 192 {
thomasstrcic 3:98f5de1dd010 193 b=N;
thomasstrcic 3:98f5de1dd010 194 *(code+1)=b;
thomasstrcic 3:98f5de1dd010 195 etat2=7;
thomasstrcic 3:98f5de1dd010 196 }
thomasstrcic 3:98f5de1dd010 197 pc.printf("etat 6 \n\r");
thomasstrcic 3:98f5de1dd010 198 break;
thomasstrcic 3:98f5de1dd010 199 case 7:
thomasstrcic 3:98f5de1dd010 200 if (N_precedent ==-3 and N!=-3)
thomasstrcic 3:98f5de1dd010 201 {
thomasstrcic 3:98f5de1dd010 202 c=N;
thomasstrcic 3:98f5de1dd010 203 *(code+2)=c;
thomasstrcic 3:98f5de1dd010 204 etat2=8;
thomasstrcic 3:98f5de1dd010 205 }
thomasstrcic 3:98f5de1dd010 206 pc.printf("etat 7 \n\r");
thomasstrcic 3:98f5de1dd010 207 break;
thomasstrcic 3:98f5de1dd010 208 case 8:
thomasstrcic 3:98f5de1dd010 209 if (N_precedent ==-3 and N!=-3)
thomasstrcic 3:98f5de1dd010 210 {
thomasstrcic 3:98f5de1dd010 211 d=N;
thomasstrcic 3:98f5de1dd010 212 *(code+3)=d;
thomasstrcic 3:98f5de1dd010 213 etat2=9;
thomasstrcic 3:98f5de1dd010 214 }
thomasstrcic 3:98f5de1dd010 215 pc.printf("etat 8 \n\r");
thomasstrcic 3:98f5de1dd010 216 break;
thomasstrcic 3:98f5de1dd010 217 case 9:
thomasstrcic 3:98f5de1dd010 218
thomasstrcic 3:98f5de1dd010 219 pc.printf("%d \n\r",a);
thomasstrcic 3:98f5de1dd010 220 pc.printf("%d \n\r",b);
thomasstrcic 3:98f5de1dd010 221 pc.printf("%d \n\r",c);
thomasstrcic 3:98f5de1dd010 222 pc.printf("%d \n\r",d);
thomasstrcic 3:98f5de1dd010 223 wait(3);
thomasstrcic 3:98f5de1dd010 224 u++;
thomasstrcic 3:98f5de1dd010 225 etat2=1;
thomasstrcic 3:98f5de1dd010 226 break;
thomasstrcic 3:98f5de1dd010 227 case 10:
thomasstrcic 3:98f5de1dd010 228 pc.printf( "code errone \n\r");
thomasstrcic 3:98f5de1dd010 229 wait(00.5);
thomasstrcic 3:98f5de1dd010 230 etat2=1;
thomasstrcic 3:98f5de1dd010 231 break;
thomasstrcic 3:98f5de1dd010 232
thomasstrcic 3:98f5de1dd010 233 }
thomasstrcic 3:98f5de1dd010 234 }
thomasstrcic 3:98f5de1dd010 235 for (i=0;i<4;i++)
thomasstrcic 3:98f5de1dd010 236 {
thomasstrcic 3:98f5de1dd010 237 pc.printf("%d \n\r",code[i]);
thomasstrcic 3:98f5de1dd010 238 }
thomasstrcic 3:98f5de1dd010 239 }
thomasstrcic 3:98f5de1dd010 240
thomasstrcic 3:98f5de1dd010 241 /*
thomasstrcic 3:98f5de1dd010 242 int bluetooth()
thomasstrcic 3:98f5de1dd010 243 {
thomasstrcic 3:98f5de1dd010 244 if ( blue.readable())
thomasstrcic 3:98f5de1dd010 245 {
thomasstrcic 3:98f5de1dd010 246 chara=blue.getc();
thomasstrcic 3:98f5de1dd010 247 val=chara-'0';
thomasstrcic 3:98f5de1dd010 248 }
thomasstrcic 3:98f5de1dd010 249 return val;
thomasstrcic 3:98f5de1dd010 250 }*/