DS18B20 with serial PC

Dependencies:   DS18B20Sensor

main1.cpp

Committer:
SereinTT
Date:
2018-12-04
Revision:
2:1573a160c634
Parent:
main.cpp@ 1:901bf6de682c

File content as of revision 2:1573a160c634:

#include "mbed.h"
#include "DS18B20Sensor.h"

// Instantiate sensor with hardware in pin p30 
DS18B20Sensor sensor(p30);

// Setup a window to the world
Serial pc(USBTX, USBRX);
//Serial pc(USBTX, USBRX);

DigitalOut myled(LED1);

int main()
{
  char sensorBuf[25];
  float num;
  // count will search for sensors, if not already called
  pc.printf("Found %d sensor/s\r", sensor.count());

  uint8_t result = sensor.startReading(true);     // start sensor readings and wait

  for (uint8_t i = 0; i < sensor.count(); i++) {
     sensor.getReading(sensorBuf, i);         // get result into buf
     pc.printf("Sensor %d : %s\r", i+1, sensorBuf);  // display it to the world

     num= atof (sensorBuf);
     pc.printf("result: %.2f\r ",  atof (sensorBuf));
  }
if (atof (sensorBuf)>25){
    myled=1;
    }
    else{
    myled=0;
    }
}