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.
Dependencies: XBeeLib mbed mbed-rtos
Revision 25:7ce844f9a1ae, committed 2018-12-04
- Comitter:
- leomerel
- Date:
- Tue Dec 04 19:33:10 2018 +0000
- Parent:
- 24:8c3f700dbfe7
- Child:
- 26:9f2c70bfb336
- Commit message:
- V5; Ajout capteur + affichage du nombre de voiture en binaire avec les led
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Dec 02 19:56:58 2018 +0000
+++ b/main.cpp Tue Dec 04 19:33:10 2018 +0000
@@ -24,15 +24,30 @@
//vert
DigitalOut feu_vert(p26);
-Thread t_nbVoiture;
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+int nbVoiture = 0;
+Thread t_affichage;
+
+Thread t_nbVoitureBouton;
+Thread t_nbVoitureCapteur;
Thread t_feuRouge;
+Timer timer;
DigitalIn boutonPlus(p24);
DigitalIn boutonMoins(p23);
+AnalogIn signal(p20);
-char data0[]="m"; // m comme "moins" - une voiture de moins
-char data1[]="p"; // p comme "plus" - une voiture de plus
-char data2[]="r"; // r comme "rouge" - confirmation que le feu est rouge
+char moins[]="m"; // m comme "moins" - une voiture de moins
+char plus[]="p"; // p comme "plus" - une voiture de plus
+char rouge[]="r"; // r comme "rouge" - confirmation que le feu est rouge
+
+int compteur =0;
+int wait_front_montant = 0;
+int wait_front_descendant = 0;
+double frequence =0;
Serial *log_serial;
XBeeZB xbee = XBeeZB(RADIO_TX, RADIO_RX, RADIO_RESET, NC, NC, 9600);
@@ -106,11 +121,11 @@
feu_orange = 0;
feu_rouge = 1;
}
- send_explicit_data_to_remote_node(xbee, remoteDevice,data2);
+ send_explicit_data_to_remote_node(xbee, remoteDevice,rouge);
}
}
-void nbVoiture() {
+void nbVoitureBouton() {
//TO DO :
// - faire un compteur de voitures interne au recepteur et envoyer ce nombre
// au coordinateur -> plus fiable en cas de perte de donnees dans un envoi
@@ -118,22 +133,97 @@
//
while(1) {
if(boutonPlus){
- send_explicit_data_to_remote_node(xbee, remoteDevice,data1);
+ nbVoiture++;
+ send_explicit_data_to_remote_node(xbee, remoteDevice,plus);
Thread::wait(500);
}
if(boutonMoins){
- send_explicit_data_to_remote_node(xbee, remoteDevice,data0);
+ nbVoiture--;
+ send_explicit_data_to_remote_node(xbee, remoteDevice,moins);
Thread::wait(500);
+ }
+ }
+}
+
+void nbVoitureCapteur() {
+ while(1){
+ int value = signal.read_u16();
+ // if(value<100){voiture++;printf("%d\r\n",value);wait(4);}
+
+ if (signal.read_u16()<100&&compteur==0){
+ timer.start();
+ compteur++;
+ wait_front_montant = 1;
+ }
+
+
+ else if (signal.read_u16()>45000&&wait_front_montant==1){
+ wait_front_montant=0;
+ wait_front_descendant = 1;
+ }
+
+ else if (signal.read_u16()<100&&wait_front_descendant==1){
+ wait_front_descendant = 0;
+ wait_front_montant=1;
+ timer.stop();
+ double t = timer.read();
+ frequence = frequence + 1/t;
+ // printf("temps %f \r\n",t);
+ // printf("frequence %f\r\n",frequence);
+ compteur++;
+ timer.reset();
+ timer.start();
}
+ if(compteur==5){
+ frequence = frequence/3;
+ double vitesse = frequence*2/19.49;
+ printf("vitesse : %f KM/H \r\n",vitesse);
+ if (vitesse>1){
+ send_explicit_data_to_remote_node(xbee, remoteDevice,plus);
+ nbVoiture++;
+ printf("vitesse : %f KM/H \r\n",vitesse);
+ Thread::wait(1000);
+ }
+ compteur=0;
+ timer.reset();
+ }
+ }
+}
+
+void affichage(){
+ while(1){
+ int a = nbVoiture;
+ if(a>=8){
+ led4=1;
+ a-=8;
+ }
+ else{led4=0;}
+ if(a>=4){
+ led3=1;
+ a-=4;
+ }
+ else{led3=0;}
+ if(a>=2){
+ led2=1;
+ a-=2;
+ }
+ else{led2=0;}
+ if(a>=1){
+ led1=1;
+ a-=1;
+ }
+ else{led1=0;}
}
}
int main()
{
connect_Xbee();
- t_nbVoiture.start(nbVoiture);
+ t_nbVoitureBouton.start(nbVoitureBouton);
+ t_nbVoitureCapteur.start(nbVoitureCapteur);
t_feuRouge.start(set_feuRouge);
+ t_affichage.start(affichage);
while (true) {
uint32_t receive_value = xbee.process_rx_frames();
}
