calculating reading from tachometer

Hey i was recently making aproject of rc car controlled by andriod app
Code sketch looks like this:

void loop(){
RemoteXY_Handler (); // the data form app
battery(); // makes remaining battery bar
meter(); // makes speedometer
if(check_battery) // check if battery is low or not
{
race(); set the forward and backward movements
steering(); set the left and right movments
}
}

The problem here is that in meter(); which calculates rpm of tyre using IR rotatory encoder,
I couldn't figure out how to calculate rpm, which function should i use ?
In meter(); if i wait to check the pulse received from sensor it will delay the whole code...

abdulsamaddabu:
The problem here is that in meter();

The real problem is that you did not post the code in the meter() function.

However you really need to post the complete program so we can know how variables are declared.

...R

Robin2:
The real problem is that you did not post the code in the meter() function.

However you really need to post the complete program so we can know how variables are declared.

…R

//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////

// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__HARDSERIAL

#include <RemoteXY.h>

// RemoteXY connection settings
#define REMOTEXY_SERIAL Serial
#define REMOTEXY_SERIAL_SPEED 38400

// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF =
{ 255,2,0,8,0,58,0,8,24,0,
5,52,46,11,46,46,93,49,24,65,
38,89,2,9,9,66,0,4,3,7,
19,205,24,67,0,16,24,19,4,34,
16,4,66,132,4,37,29,23,207,203,
129,0,2,23,14,4,227,66,97,116,
116,101,114,121,0 };

// this structure defines all the variables of your control interface
struct {

// input variable
int8_t joystick_x; // =-100…100 x-coordinate joystick position
int8_t joystick_y; // =-100…100 y-coordinate joystick position

// output variable
uint8_t led_r; // =0…255 LED Red brightness
uint8_t led_g; // =0…255 LED Green brightness
int8_t battery; // =0…100 battery position
char text[4]; // string UTF8 end zero
int8_t meter; // =0…100 battery position

// other variable
uint8_t connect_flag; // =1 if wire connected, else =0

} RemoteXY;
#pragma pack(pop)

/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////

//Pins
int pwm_1=6; // pwm pin for motor 1
int a_1=7; // enable pin 1 for motor 1
int b_1=8; // enable pin 2 for motor 1
int a_2=9; // enable pin 1 for motor 2
int b_2=10; // enable pin 2 for motor 2
int pwm_2=11; // pwm pin for motor 2
int speed_1=0; // speed variable for motor 1
int speed_2=0; // speed variable for motor 2
int volts=A0; // battery volt pin
int rpm=A1; // rpm pin

void setup()
{
RemoteXY_Init ();
pinMode(pwm_1,OUTPUT);
pinMode(a_1,OUTPUT);
pinMode(b_1,OUTPUT);
pinMode(a_2,OUTPUT);
pinMode(b_2,OUTPUT);
pinMode(pwm_2,OUTPUT);
pinMode(volts,INPUT);
}

void loop(){
RemoteXY_Handler ();

}

int check_battery(){
if(analogRead(volts)>680){
return 1;
}
if(analogRead(volts)<670){
return 0;
}
}

void meter(){

}

void battery(){
RemoteXY.battery = map(analogRead(volts), 670 ,800 ,0, 100); // adjust battery battery range
}

void race(){
if (RemoteXY.joystick_y > 40) // Adjust Joystick Position
{
digitalWrite(a_1, LOW);
digitalWrite(b_1, HIGH);
digitalWrite(a_2, LOW);
digitalWrite(b_2, HIGH);
speed_1 = map(RemoteXY.joystick_y, 40, 100, 100, 255); // Adjust Sensitivity
speed_2 = map(RemoteXY.joystick_y, 40, 100, 100, 250); // Adjust Sensitivity
}
else if (RemoteXY.joystick_y < -40) // Adjust Joystick Position
{
digitalWrite(a_1, HIGH);
digitalWrite(b_1, LOW);
digitalWrite(a_2, HIGH);
digitalWrite(b_2, LOW);
speed_1 = map(RemoteXY.joystick_y, -40, -100, 100, 255); // Adjust Sensitivity
speed_2 = map(RemoteXY.joystick_y, -40, -100, 100, 250); // Adjust Sensitivity
}
else
{
digitalWrite(a_1, LOW);
digitalWrite(b_1, LOW);
digitalWrite(a_2, LOW);
digitalWrite(b_2, LOW);
speed_1 = 0;
speed_2 = 0;
}
}

void steering(){
if(RemoteXY.joystick_x > 80) // Adjust Joystick Position
{
digitalWrite(a_1, LOW);
digitalWrite(b_1, HIGH);
digitalWrite(a_2, HIGH);
digitalWrite(b_2, LOW);
speed_1 = 255;
speed_2 = 255;
}
else if(RemoteXY.joystick_x < -80) // Adjust Joystick Position
{
digitalWrite(a_1, HIGH);
digitalWrite(b_1, LOW);
digitalWrite(a_2, LOW);
digitalWrite(b_2, HIGH);
speed_1 = 255;
speed_2 = 255;
}
}

That code defines 'meter' as both an integer variable and a function returning no value. Can't be both.

@abdulsamaddabu, to make it easier for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to a text editor.

…R