Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

2 What are the implications for logistics strategy?

Answered: 1 week ago