Hello Arduino guys,
I found programming for a metal detector on an internet website, but unfortunately I do not know how the program works. That's why I ask you, would you help me?
Thanks for your help!
Best regards ,
an Arduino freshman
#define SET(x,y) (x |=(1<<y))
#define CLR(x,y) (x &= (~(1<<y)))
#define CHK(x,y) (x & (1<<y))
#define TOG(x,y) (x^=(1<<y))
unsigned long t0=0;
int t=0;
unsigned char tflag=0;
float SENSITIVITY= 1000.0;
SIGNAL(TIMER1_COMPA_vect)
{
OCR1A+=1000;
t=micros()-t0;
t0+=t;
tflag=1;
}
void setup()
{
pinMode(13,OUTPUT);
digitalWrite(12,HIGH);
TCCR1A=0;
TCCR1B=0x07;
SET(TIMSK1,OCF1A);
}
//-Float ABS
float absf(float f)
{
if(f<0.0)
return -f;
else
return f;
}
int v0=0;
float f=0;
unsigned int FTW=0;
unsigned int PCW=0;
unsigned long timer=0;
void loop()
{
if(tflag)
{
if(digitalRead(12)==LOW)
v0=t;
f=f*0.9+absf(t-v0)*0.1;
tflag=0;
float clf=f*SENSITIVITY;
if(clf>10000)
clf=10000;
FTW=clf;
}
if(millis()>timer)
{
timer+=10;
PCW+=FTW;
if(PCW&0x8000)
{
digitalWrite(13,HIGH);
PCW&=0x7fff;
}
else
digitalWrite(13,LOW);
}
}