App S5 / Mbed 2 deprecated S05APP2

Dependencies:   mbed mbed-rtos

Revision:
20:8815d51406a9
Parent:
19:abddc058f6d1
Child:
21:3b9a50b245f8
--- a/main.cpp	Mon Jan 30 17:04:20 2017 +0000
+++ b/main.cpp	Mon Jan 30 17:14:59 2017 +0000
@@ -3,7 +3,13 @@
 #include "Ticker.h"
 #include "Serial.h"
 #include "rtos.h"
-
+ 
+Serial pc(USBTX, USBRX); // tx, rx
+Ticker ticker;
+DigitalIn en_1(p15);
+DigitalIn en_2(p16);
+AnalogIn ea_1(p19);
+AnalogIn ea_2(p20);
 Thread *t1;
 Thread *t2;
 Mutex mutex; 
@@ -17,7 +23,7 @@
     uint8_t broche;      // Le numéro de la broche
 } mail_t;
 
-Mail<mail_t, 16> mail_box;
+Mail<mail_t, 4> mail_box;
 
 // -------------------------------------------------------
 // -------------------------------------------------------
@@ -40,8 +46,6 @@
     float echantillons1[5];
     float echantillons2[5];
     float seuil = 0.125;
-        AnalogIn ea_1(p19);
-        AnalogIn ea_2(p20);
     
     while (true) {        
         /*** Synchronisation sur la période d'échantillonnage ***/
@@ -79,9 +83,7 @@
 
 void lecture_num(void const *args) {  
     bool valeurs[2] = {0};
-        DigitalIn en_1(p15);
-        DigitalIn en_2(p16);
-        
+  
     while (true) {
         /*** Synchronisation sur la période d'échantillonnage ***/
         Thread::signal_wait(0x1);
@@ -114,8 +116,7 @@
 }
 
 void collection(void const *args) {
-        Serial pc(USBTX, USBRX); // tx, rx
-    while (true) {  
+    while (true) {
         /*** Attente et lecture d'un événement ***/
         osEvent evt = mail_box.get();
         if (evt.status == osEventMail) {
@@ -149,6 +150,7 @@
 
 int main() {
     /*** Démarrage des tâches ***/
+
     Thread t_lectureNum(lecture_num);
     Thread t_lectureAnalog(lecture_analog);
     Thread t_collection(collection);
@@ -157,7 +159,6 @@
     t2 = &t_lectureAnalog;
     
     /*** Initialisation du RTC ***/
-        Ticker ticker;
     set_time(1485514920);  // Set RTC time to...
     ticker.attach(&alarm, 0.05);