ultimaact
Dependencies: mbed Adafruit_GFX DS1820
Revision 10:db8ef252faba, committed 2021-12-14
- Comitter:
- davidmateos
- Date:
- Tue Dec 14 09:38:10 2021 +0000
- Parent:
- 9:d651ed116942
- Commit message:
- con temeratura
Changed in this revision
DS1820.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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DS1820.lib Tue Dec 14 09:38:10 2021 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/hudakz/code/DS1820/#74d2a4ac7f32
--- a/main.cpp Tue Dec 14 08:57:43 2021 +0000 +++ b/main.cpp Tue Dec 14 09:38:10 2021 +0000 @@ -1,6 +1,6 @@ #include "mbed.h" #include "hcsr04.h" - +#include "DS1820.h" #include "Adafruit_SSD1306.h" @@ -33,7 +33,9 @@ DigitalOut step(D13); DigitalOut dir(D12); DigitalOut enable(D11); - +DigitalOut led(LED1); +DS1820 ds1820(D10); // substitute PA_9 with actual mbed pin name connected to the DS1820 data pin +float temp = 0; int contador=0; @@ -133,6 +135,33 @@ gOled.printf("Hola\n"); //pc.printf("Estado cerrada\n"); + int error = 0; + pc.baud(115200); + + if(ds1820.begin()) { + while(1) { + ds1820.startConversion(); // start temperature conversion from analog to digital + wait(1.0); // let DS1820 complete the temperature conversion + error = ds1820.read(temp); // read temperature from DS1820 and perform cyclic redundancy check (CRC) + switch(error) { + case 0: // no errors -> 'temp' contains the value of measured temperature + pc.printf("temp = %3.1f C\r\n", temp); + break; + case 1: // no sensor present -> 'temp' is not updated + pc.printf("no sensor present\n\r"); + break; + case 2: // CRC error -> 'temp' is not updated + pc.printf("CRC error\r\n"); + } + led = !led; + } + } else + pc.printf("No DS1820 sensor found!\r\n"); + + + + + while(1) { distancia=usensor.get_dist_cm();