Programme principal

Dependencies:   contest_IOT mbed

Dependents:   contest_IOT

Fork of contest_IOT by Contest IOT GSE5

Files at this revision

API Documentation at this revision

Comitter:
Mickado
Date:
Sun Oct 11 11:18:29 2015 +0000
Parent:
1:e9d1c42a73ae
Commit message:
Premi?re version projet

Changed in this revision

HCSR04.lib Show annotated file Show diff for this revision Revisions of this file
contest.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r e9d1c42a73ae -r 35466dfc81fe HCSR04.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.lib	Sun Oct 11 11:18:29 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/Contest-IOT-GSE5/code/HCSR04/#79e45473cfab
diff -r e9d1c42a73ae -r 35466dfc81fe contest.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/contest.lib	Sun Oct 11 11:18:29 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/teams/Contest-IOT-GSE5/code/contest_IOT/#04b305a9368f
diff -r e9d1c42a73ae -r 35466dfc81fe main.cpp
--- a/main.cpp	Fri Feb 28 06:52:34 2014 +0000
+++ b/main.cpp	Sun Oct 11 11:18:29 2015 +0000
@@ -1,21 +1,61 @@
 #include "mbed.h"
+#include "hcsr04.h"
+#include "contest.h"
+#include <math.h>
+
+#define ECHO_1  PB_9
+#define ECHO_2  PA_5
+#define TRIG_1  PB_8
+#define TX      PA_2
+#define RX      PA_3
+#define PUSH    USER_BUTTON //PC_13
+#define LED_1   LED1
 
 //------------------------------------
 // Hyperterminal configuration
 // 9600 bauds, 8-bit data, no parity
 //------------------------------------
 
-Serial pc(SERIAL_TX, SERIAL_RX);
- 
-DigitalOut myled(LED1);
- 
+
+Serial pc(TX, RX);          //UART
+DigitalOut led(LED_1);      //Led d'état
+InterruptIn button(PUSH);   //Bouton d'interruption
+
+HCSR04 sensor(TRIG_1, ECHO_1); 
+Control ctrl;
+
+void changeEtat(){
+    pc.printf("\033[2J");   //Efface la console
+    ctrl.marcheArret();
+}
+float distancePrec=0;
+
+
+
 int main() {
-  int i = 1;
-  pc.printf("Hello World !\n");
-  while(1) { 
-      wait(1);
-      pc.printf("This program runs since %d seconds.\n", i++);
-      myled = !myled;
-  }
+    float distance;
+    pc.printf("\033[2J");       //Efface la console
+    pc.printf("\033[0;0H");     //Place le curseur à 0:0
+    pc.printf("\033[?25l");     //Cache le curseur
+    //pc.printf("\033[?25h");   //Affiche le curseur
+    pc.printf("Initialisation...   ");
+    
+    //Initialisation de l'interruption : en appuyant sur le bouton bleu de la carte, le programme change d'état
+    button.fall(&changeEtat);
+    
+    pc.printf("Ready !\n\r");
+    
+    //Boucle d'exécution du programme
+    while(1) { 
+        if(ctrl.isActive()){
+            led=1;
+            distance = sensor.distance();               //Mesure de la distance
+            print_distance(distance, distancePrec);     //Affichage à l'écran
+            distancePrec=distance;                      //Mise en mémoire
+        }else{
+            led=0;
+        }
+    wait(0.001);
+    }
 }
  
\ No newline at end of file
diff -r e9d1c42a73ae -r 35466dfc81fe mbed.bld
--- a/mbed.bld	Fri Feb 28 06:52:34 2014 +0000
+++ b/mbed.bld	Sun Oct 11 11:18:29 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/ed8466a608b4
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file