#pragma once #include "Things/TouchSensor.h" namespace RoboidControl { namespace Arduino { /// @brief An HC-SR04 ultrasonic distance sensor class UltrasonicSensor : public TouchSensor { public: /// @brief Setup an ultrasonic sensor /// @param participant The participant to use /// @param pinTrigger The pin number of the trigger signal /// @param pinEcho The pin number of the echo signal UltrasonicSensor(Participant* participant, unsigned char pinTrigger, unsigned char pinEcho); // parameters /// @brief The distance at which the object is considered to be touched float touchDistance = 0.2f; // state /// @brief The last read distance float distance = 0; /// @brief erform an ultrasonic 'ping' to determine the distance to the /// nearest object /// @return the measured distance in meters to the nearest object float GetDistance(); /// @copydoc RoboidControl::Thing::Update(unsigned long currentTimeMs) virtual void Update(unsigned long currentTimeMs, bool recursive = false) override; protected: /// @brief The pin number of the trigger signal unsigned char pinTrigger = 0; /// @brief The pin number of the echo signal unsigned char pinEcho = 0; }; } // namespace Arduino } // namespace RoboidControl