Hello I am trying program my arduino MEGA 2560 for sensing a distance of an object in cms and maintain pressure inside a chamber according to the distance sensed. So I used 1) Ultrasonic distance sensor 2) pressure MAP sensor which gives analog values based on the pressure readings 3) A servo to release the pressure inside the chamber using a valve 4) relay to increase the pressure inside the chamber. I want the device to work whenever it senses an object at a particular distance it needs to decide what pressure it should be maintaining inside the chamber (Say if the pressure is more the release valve will open or if the pressure is less the relay should work) So I took the readings by observing the MAP sensor readings and the distance sensor readings which results in a linear graph with a relation (Y=199.81*D-2757). I tried to multiplex all these programs into a single program but have got errors in the function bit. Please help me to solve this.. I am attaching the source code with this message as a wordpad file. If you edit it please highlight it so that it can be easy for me to understand
It says 'microsecondToCentimeters' was not declared in this scope
sketch_aug02a.ino: In function 'void loop()':
sketch_aug02a:39: error: 'microsecondsToCentimeters' was not declared in this scope
sketch_aug02a:83: error: a function-definition is not allowed here before '{' token
Someone already told you what part of your problem was. The second problem was adding a semicolon at the end of your method definition
long microsecondsToCentimeters(long microseconds); <-Right Here, remove this
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}