Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
func.cpp
00001 #include "mbed.h" 00002 #include "func.h" 00003 #include "time.h" 00004 00005 int etat=0; 00006 00007 float distance=32; 00008 int vitrand1=(rand()%60)+20; 00009 int vitrand2=(rand()%60)+20; 00010 int cligne=rand()%15; 00011 int td12=0; 00012 00013 00014 void vite(void){ 00015 MotD.pulsewidth_us(vitrand1); 00016 MotG.pulsewidth_us(vitrand2); 00017 vitrand1=(rand()%50)+30; 00018 vitrand2=(rand()%50)+30; 00019 } 00020 00021 void attend(void){ 00022 if(vitrand1>vitrand2){ 00023 wait(40*1/vitrand1); 00024 } 00025 else wait(40*1/vitrand2); 00026 } 00027 00028 void clignote(void){ 00029 cligne=rand()%15; 00030 leds.write(cligne); 00031 } 00032 00033 void fou(void){ 00034 distance=srf.read(); 00035 switch(etat){ 00036 case 0 : if(distance > 45){ etat = 1; }; break; 00037 case 1 : if(distance < 45){ etat = 0; }; break; 00038 } 00039 00040 switch(etat){ 00041 case 0 : t2.detach(); 00042 td12=0; 00043 SensG.write(1); 00044 SensD.write(0); 00045 MotD.pulsewidth_us(50); 00046 MotG.pulsewidth_us(50); 00047 attend(); 00048 break; 00049 case 1 : if(td12==0){SensD.write(0); SensG.write(0); t2.attach(&vite,0.5); td12=1;} break; 00050 } 00051 /* printf("sensrand = %d\n\r",sensrand); 00052 printf("vitrand = %d\n\r",vitrand); 00053 */ 00054 00055 printf("Tension Batterie:%g\n\r",(Vbat.read()*13300*3.3)/3300); 00056 //wait(1); 00057 wait_ms(30); 00058 }
Generated on Sat Jul 16 2022 18:24:34 by
1.7.2