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.
Diff: Capteurs/Infra.cpp
- Revision:
- 0:1cfd66c3a181
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Capteurs/Infra.cpp Wed May 22 16:54:27 2019 +0000 @@ -0,0 +1,33 @@ +#include "Infra.h" +#include <math.h> + +// Constructeur: +Infra::Infra(PinName pin) + : m_analog(pin), + m_isOn(true), + m_distdetect(30.0f), + m_detect(false) {} + +// Mesure: +bool Infra::mesure() { + // Mesure: + m_voltage = m_analog.read(); + m_voltage = (float)m_voltage * (float)3.3; + m_distance = (float)29.988 * powf(m_voltage, -1.173) / 2.0f; + + // Détection: + if (m_isOn) m_detect = m_distance < m_distdetect; + else m_detect = false; + + return m_detect; +} + +// Setters: +void Infra::setDistDetect(float detect) { m_distdetect = detect; } +void Infra::on() { m_isOn = true; } +void Infra::off() { m_isOn = false; } + +// Getters: +float Infra::getDistance() { return m_distance; } +float Infra::getVoltage() { return m_voltage; } +float Infra::getDistdetect() { return m_distdetect; }