Hi guys.
I have the following error while compiling the code:
First_Test.cpp.o: In function `__static_initialization_and_destruction_0':
C:\Program Files (x86)\Arduino/First_Test.ino:11: undefined reference to `SFR_Control::SFR_Control(int)'
First_Test.cpp.o: In function `loop':
C:\Program Files (x86)\Arduino/First_Test.ino:19: undefined reference to `SFR_Control::Check_2_close()'
The Sketch file is:
#include "C:\Program Files (x86)\Arduino\libraries\SFR05\SFR05.h"
#include <CAR_LCD_Display.h>
#include <LiquidCrystal.h>
#include <Arduino.h>
#define Trg_pin 3
CAR_LCD_CONTROL LCD (32,30,28,26,24,22);
SFR_Control Front (3);
void setup ()
{
Serial.begin(9600);
}
void loop ()
{
bool i = Front.Check_2_close() ;
if (i)
{
LCD.Write_Direct("Too Close",0);
}
}
the Header file is:
#ifndef _SFR_05_H
#define _SFR_05_H
#define DEBUG
typedef unsigned char BYTE;
#define Max_Str_Len 40
#define Minumum_Distance 30 //cm
#define Speed_Of_Sound 0.017 // cm/us/2
class SFR_Control {
public:
SFR_Control(int tgr_pin);//
bool Preform_Measure (void);
bool Check_2_close();
void Set_Distance_Meas (int Dist);
void Set_Startup_Meas (int Dist);
void Set_Shutdown_Meas (int Dist);
int Get_Distance_Meas ();
int Get_Startup_Meas ();
int Get_Shutdown_Meas ();
void Set_Triger_pin (int trg);
int Get_Triger_pin ();
int * Get_Median_arr ();
void Set_Median_arr (int data, int index);
// Variables
int Distance_Measured;
int Startup_Meas;
int Shutdown_Meas;
int Triger_pin;
int Median_arr[11];
};
#endif /* not defined */
and the implementation is:
#include "SFR05.h"
#include "Arduino.h"
SFR05::SFR05(int tgr_pin)
{
this->Set_Triger_pin(tgr_pin);
pinMode(tgr_pin, OUTPUT);
digitalWrite(tgr_pin, LOW);
}
bool SFR05::Preform_Measure(void)
{
int tmp;
if (DEBUG) Serial.print("Measuring Distance sq. start");
digitalWrite(this->Get_Triger_pin(), LOW);
delayMicroseconds(2);
digitalWrite(this->Get_Triger_pin(), HIGH);
delayMicroseconds(10);
digitalWrite(this->Get_Triger_pin(), LOW);
pinMode(this->Get_Triger_pin(), INPUT);
tmp = pulseIn(this->Get_Triger_pin(), HIGH);
this->Set_Distance_Meas ( tmp / 58); // Speed of sound 0.034 [cm/us] divide by 2 is = 0.017 which is aprox 1/58;
if (tmp == 0) return false;
return true;
}
bool SFR05::Check_2_close()
{
int meas;
int len = sizeof(this->Get_Median_arr()) / sizeof (this->Get_Median_arr()[0]);
for (int i = 0; i < len; i++)
{
meas=this->Preform_Measure();
this->Set_Median_arr(meas, i);
}
//Insertion Sort
{
int key;
int i;
for (int j = 1; j<len; j++)
{
key = this->Get_Median_arr()[j];
i = j - 1;
while ((i >= 0) && (this->Get_Median_arr()[i]>key))
{
this->Get_Median_arr()[i + 1] = this->Get_Median_arr()[i];
i--;
}
this->Get_Median_arr()[i + 1] = key;
}
}
//int place =;
if (this->Get_Median_arr()[len/2] <= Minumum_Distance)
{
//CAR_LCD05::Write_Direct("Too Close Break!!!",0);
return true;
}
return false;
}
void SFR05::Set_Distance_Meas(int Dist)
{
Distance_Measured = Dist;
}
void SFR05::Set_Startup_Meas(int Dist)
{
Startup_Meas = Dist;
}
void SFR05::Set_Shutdown_Meas(int Dist)
{
Shutdown_Meas = Dist;
}
int SFR05::Get_Distance_Meas()
{
return Distance_Measured;
}
int SFR05::Get_Startup_Meas()
{
return Startup_Meas;
}
int SFR05::Get_Shutdown_Meas()
{
return Shutdown_Meas;
}
void SFR05::Set_Triger_pin(int trg)
{
Triger_pin = trg;
}
int SFR05::Get_Triger_pin()
{
return Triger_pin;
}
int * SFR05::Get_Median_arr()
{
return Median_arr;
}
void SFR05::Set_Median_arr(int data, int index)
{
Median_arr[index] = data;
}
#endif /* not defined _CAR_LCD_DISPLAY_H */
I cant figure out where is the problem coming from, please your advise.