oki

Dependencies:   mbed

Fork of ProjetInfo2_Multi by julien bitoun

Committer:
thomasstrcic
Date:
Tue Jun 12 14:45:54 2018 +0000
Revision:
4:23e955d622f9
Parent:
2:ae058dfdebac
fuck bitoun

Who changed what in which revision?

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