-
Notifications
You must be signed in to change notification settings - Fork 1
/
wombatpi.ino
92 lines (68 loc) · 1.92 KB
/
wombatpi.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
----------------------------------------------------------------------------
WOMBAT PI Metal detector
Arduino UNO R4 Minima Version
wombatpi.net
Last Modified: 27-Sep-2024
----------------------------------------------------------------------------
*/
#define VERSION "27SEP2024"
#include "wombat.h"
#include "wombat_analog.h"
#include "target_sense.h"
#define BAUD_RATE (115200)
#define MAX_TX_BUFFER (30)
char txBuffer[MAX_TX_BUFFER];
void setup()
{
Serial.begin(BAUD_RATE);
delay(200) ; // charge the capacitor
setupSample();
setup_soundWave(); // Audio and pulsing
// Not used
//
if(WIFI_SERIAL_ENABLED)
{
Serial1.begin(BAUD_RATE);
}
}
void loop()
{
static int soundUpdateCount = -4000; // this counts up, and provides an initial delay before outputting sound
static double sum = 0.0;
static int serialCheckCount = 0; // check the serial port periodically
static int printOutCount = 0;
static int newAverageCounter;
static double maxF;
static int medianCounter = 0;
static int loopCounter = 0;
int oldSample;
int index = 0;
double tempF ;
double signal;
if(sampleReady)
{
sampleReady = false;
theCoil.doSampleAveraging();
// Do our Discrimination and Target ID here if it's time
//
// i.e If 600 Hz pulse rate, with 50-sample buffer, we will do this 600/50 = 12 times per second)
//
if (printOutCount++ > SAMPLE_BUFFER_LENGTH)
{
printOutCount = 0;
theCoil.targetSense();
//theCoil.debug();
}
// start off as large negative number and we don't need a separate startup counter
//
if (soundUpdateCount++ > SOUND_UPDATE_COUNT)
{
soundUpdateCount = 0;
//do the audio update
//
tempF = theCoil.soundSignal();
soundAlgorithm3(theCoil.soundSignalValue, theCoil.soundSignalConductivity);
}
}
}