Projet Long pour AGRAL

Dependencies:   mbed OneWire DHT22 TSL2561 SSD1306

Revision:
2:1e52e7fab454
Parent:
1:1b64ee29ae15
Child:
3:e369ee47403e
--- a/main.cpp	Mon Sep 11 15:31:09 2017 +0000
+++ b/main.cpp	Tue Sep 12 07:21:14 2017 +0000
@@ -1,16 +1,31 @@
 #include "mbed.h"
+#include "OneWire.h"
+ 
+OneWire owBus(PA_8);
 
 DigitalOut myled(PB_3);
 AnalogIn Hum(PA_0); //Entrée du capteur 
 Serial pc(PA_2,PA_3); //Tx,Rx
 
 int main() {
+    char _id[16];
+    DeviceAddresses* devAddresses = owBus.getFoundDevAddresses();
+    uint8_t foundNum = owBus.getFoundDevNum();
+    printf("OneWire: found %d devices\r\n", foundNum);
     while(1) {
-        myled = 1; // LED is ON
-        wait(1.0); // 200 ms
-        myled = 0; // LED is OFF
-        wait(1.0); // 1 sec
+        OneWireDeviceTemperature::startConversationForAll(&owBus, OWTEMP_11_BIT);
+        for (uint8_t i = 0; i < foundNum; i++) {
+            OneWireDevice* owDevice = OneWireDeviceFactory::init(&owBus, (*devAddresses)[i]);
+            
+            if (owDevice->getFamily() != ONEWIRE_DS18B20_FAMILY)    // currently only DS18B20 supports
+                continue;
+ 
+            owDevice->generateId(_id);
+            printf("OneWire: device #%s = %.4f*C\r\n", _id, (float) owDevice->sendGetCommand(GET_TEMPERATURE));
+            delete owDevice;            
+        }
         
-        pc.printf("%f",Hum.read()); //Lit l'entrée du capteur et l'affiche
+        wait(5);
     }
 }
+