Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Ping.h :: A library for using a Parallax PING))) sensor in robotic applications.
- *
- * @author Tom Malone <tmalone+arduino.software@gmail.com>
- * @copyright Released into the public domain.
- */
- #ifndef Ping_h
- #define Ping_h
- #if ARDUINO < 100
- #include <WProgram.h>
- #else
- #include <Arduino.h>
- #endif
- #include <string.h>
- class Ping {
- private:
- uint8_t _pin; // Which pin the Ping))) sensor is connected to.
- String _distanceUnit; // The unit of measurement for returning distance to obstacle.
- // Possible units: cm, in, or raw.
- // cm == centimeters
- // in == inches
- // raw == return the raw time of the pulse duration in microseconds
- float _centimetersPerSecond; // The speed of sound we're using (because its variable, by a number of factors), converted to cm/second.
- int _collisionThreshold; // How close the robot is allowed to get to an obstacle before forcing it to turn away.
- float _centimetersToInches(float cmValue); // Converts centimeters to inches.
- unsigned long _pulseDuration; // Stores the time it takes the ultrasound to travel to the obstacle and back.
- public:
- Ping(uint8_t pin, String distanceUnit); // The constructor method
- unsigned long ping(); // Sends the actual Ping))) pulse.
- void activate(); // The activation method take care of activating the Ping))) sensor with a brief PWM pulse.
- uint8_t getCollisionThreshold(); // Returns the value of _collisionThreshold.
- void setCollisionThreshold(uint8_t threshold); // Sets the value of _collisionThreshold.
- uint16_t pulseTimeToCentimeters(unsigned long pulseDuration); // Converts the pulse duration to centimeters
- float pulseTimeToInches(unsigned long pulseDuration); // Converts the pulse duration to inches.
- String getDistanceUnit(); // Gets the distance unit the user wants his distances to be returned in.
- String setDistanceUnit(String distanceUnit); // Sets the distance unit the user wants his distances to be turned in.
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement