Question: I need to create a cpp file and a header file that work with the given code. Need super help. Coding is in C++ -

I need to create a cpp file and a header file that work with the given code. Need super help. Coding is in C++ - We are trying to program an arduino to read out the proximity sensor HCSR04.

#include "HCSR04.h"//include your proximity sensor library

#define echoPin 8 // This is the echo pin #define triggerPin 9 // This is the trigger pin

HCSR04ProxSensor distanceSensor(echoPin,triggerPin);//here we call the constructor to instantiate a sensor named "distanceSensor"

/***************************setup function****************************************************/

void setup() { Serial.begin(9600);//start serial communication }

/***************************main loop*********************************************************/

void loop() { Serial.print("The distance is : "); float distance = distanceSensor.readSensor();//here we call the 'readSensor' method to determine the distance Serial.print(distance);// send the measurement to the serial monitor Serial.println(" cm"); if (distanceSensor.getLastValue() - distance > 1) {Serial.println("object is approaching");}//here we call the 'getLastValue' method to determine the direction of motion if (distanceSensor.getLastValue() - distance < -1) {Serial.println("object is retracting");}

delay(500); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!