This segment focuses on the development of C++ libraries for the control of devices connected to the Arduino. Goals:

Learn to design C++ libraries.

Design a library for the control of an Arduino Kit component.

In-Class Project:

Write a library for the control of the ultrasound proximity sensor in the Arduino Kit.

Tasks:

Write a class for proximity sensor. Call it “HCSR04ProxSensor”

It is good practice to use the actual device name for such a library.

Develop the following methods:

Constructor: void HCSR04ProxSensor:: HCSR04ProxSensor(int triggerPin, int echoPin). This is the ‘constructor’, which defines the pins that are used to connect the sensor

int HCSR04ProxSensor:: readSensorInches(). This reads the sensor in inch units.

float HCSR04ProxSensor:: readSensorCentimeters(). This reads the sensor in cm units.

float HCSR04ProxSensor::getLastValue(). This returns the last measurement that was made. this is a convenient method if you wanted, for example, write some code that measures distance changes. You could ask the sensor: ‘what did you measure the last time’, and then compare with the current value that would be returned by . readSensorInches().

Generate the header .h file and the .cpp file and save them in their own folder in the Library folder.

Modify the provided code including the library and experiment with the methods.