View difference between Paste ID: WyzrTB1P and
SHOW: | | - or go back to the newest paste.
1-
1+
/**
2
 * Ping.h :: A library for using a Parallax PING))) sensor in robotic applications.
3
 * 
4
 * @author Tom Malone <tmalone+arduino.software@gmail.com>
5
 * @copyright Released into the public domain.
6
 */
7
8
#ifndef Ping_h
9
#define Ping_h
10
11
#if ARDUINO < 100
12
#include <WProgram.h>
13
#else
14
#include <Arduino.h>
15
#endif
16
17
#include <string.h>
18
19
class Ping {
20
21
    private:
22
	    uint8_t _pin;	// Which pin the Ping))) sensor is connected to.
23
	    String _distanceUnit;    // The unit of measurement for returning distance to obstacle. 
24
																    // Possible units: cm, in, or raw.
25
																    // cm == centimeters
26
																    // in == inches
27
																    // raw == return the raw time of the pulse duration in microseconds
28
	    float _centimetersPerSecond;	// The speed of sound we're using (because its variable, by a number of factors), converted to cm/second.
29
	    int _collisionThreshold;	// How close the robot is allowed to get to an obstacle before forcing it to turn away.
30
	    float _centimetersToInches(float cmValue);	// Converts centimeters to inches.
31
	    unsigned long _pulseDuration;	// Stores the time it takes the ultrasound to travel to the obstacle and back.
32
	    
33
    public:
34
	    Ping(uint8_t pin, String distanceUnit);	// The constructor method
35
	    unsigned long ping();	// Sends the actual Ping))) pulse.
36
	    void activate();	// The activation method take care of activating the Ping))) sensor with a brief PWM pulse.
37
	    uint8_t getCollisionThreshold();	// Returns the value of _collisionThreshold.
38
	    void setCollisionThreshold(uint8_t threshold);	// Sets the value of _collisionThreshold.
39
	    uint16_t pulseTimeToCentimeters(unsigned long pulseDuration);	// Converts the pulse duration to centimeters
40
	    float pulseTimeToInches(unsigned long pulseDuration);	// Converts the pulse duration to inches.
41
	    String getDistanceUnit();	// Gets the distance unit the user wants his distances to be returned in.
42
	    String setDistanceUnit(String distanceUnit);	// Sets the distance unit the user wants his distances to be turned in.
43
};
44
45
#endif