Metal detector

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? :confused:
Thanks for your help!

Best regards ,
an Arduino freshman :slight_smile:

#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);
}
}

Please read this:-
How to use this forum
Because your post is breaking the rules about posting code.

Also you need to post the schematic of the hardware because the software alone only tells half the story.

Tell us if it actually works or not, then it may be worth some time trying to discover how it works.

What is connected to pin 12?

Paul

here is the gif

Damalama:
I do not know how the program works.

So you have built it and it works ?

You should understand that there is a lot of programs out there published that, shock horror, may not work.

And if you 'find' a program its useful to everyone else if you tell us where you 'found' it, i.e provide a link.

I see 30 turns on a bucket. I wonder how many sizes of buckets there are in the world and what they are made of?

Paul