Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Example usage
main.cpp
#include "mbed.h" #include "TMP06.h" int main() { TMP06 temp_sensor(P0_1); float temperature; while (true) { if(temp_sensor.read(&temperature) == SUCCESS) { printf("Temperature: %f\n", temperature); } else { printf("Error!\n"); } ThisThread::sleep_for(2000); } }
TMP06.cpp
- Committer:
- Pawel Zarembski
- Date:
- 2020-02-25
- Revision:
- 1:82fcfd05add8
- Parent:
- 0:cee46eec60a8
- Child:
- 2:1ff2f041925a
File content as of revision 1:82fcfd05add8:
/* Copyright (C) 2020 Arrow Electronics */ #include "TMP06.h" TMP06::TMP06(PinName pin) : _pwm_pin(pin), _semaphore(0, 1) { } TMP06::~TMP06() { } int TMP06::read(float *temperature) { _pwm_pin.disable_irq(); _first_run = true; _timer1.reset(); _timer2.reset(); _pwm_pin.rise(callback(this, &TMP06::on_rise)); _pwm_pin.fall(callback(this, &TMP06::on_fall)); _pwm_pin.enable_irq(); // 200 - period of sensor should be around 100, // more would means there is some kind of issue if (_semaphore.try_acquire_for(SEM_TIMEOUT_MS)) { // based on TMP05/TMP06 datasheet rev. C *temperature = (421 - 751 * ((float)_timer1.read_us() / (float)_timer2.read_us())); return SUCCESS; } else { return FAILURE; } } void TMP06::on_rise() { if (_first_run) { _timer1.start(); _first_run = false; } else { _timer2.stop(); _semaphore.release(); _pwm_pin.disable_irq(); } } void TMP06::on_fall() { _timer1.stop(); _timer2.start(); }