-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathInductor.h
68 lines (55 loc) · 1.74 KB
/
Inductor.h
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
#pragma once
#include "Definitions.h"
class Inductor
{
public:
static bool DetectInductor()
{
for (size_t Index = 0; Index != ArrayCount(MutuallyExclusivePins); ++Index)
{
auto
FirstPin = MutuallyExclusivePins[Index].First,
SecondPin = MutuallyExclusivePins[Index].Second,
ThirdPin = MutuallyExclusivePins[Index].Third;
if (SetUpAndExclusivelyMeasureInductance(FirstPin, SecondPin, ThirdPin))
{
return true;
}
}
return false;
}
private:
static bool MeasureInductance(uint8_t FromPin, uint8_t ToPin)
{
digitalWrite(FromPin, HIGH);
digitalWrite(ToPin, LOW);
delay(100);
digitalWrite(FromPin, LOW);
digitalWrite(ToPin, LOW);
delay(StablisationDelay);
auto PreviousVoltage = MeasureVoltage(FromPin, ToPin);
auto PreviousCurrent = MeasureCurrent(FromPin, ToPin);
delay(1);
auto NewVoltage = MeasureVoltage(FromPin, ToPin);
auto NewCurrent = MeasureCurrent(FromPin, ToPin);
auto Inductance = ((PreviousVoltage + NewVoltage) / 2) / (PreviousCurrent - NewCurrent);
if (IsReadingValid(Inductance))
{
Display::GetInstance().println(String("Inductor found between pins ") + FromPin + " and " + ToPin);
Display::GetInstance().println(String("Inductance: ") + Inductance + "mH");
return true;
}
return false;
}
static bool SetUpAndExclusivelyMeasureInductance(uint8_t FromPin, uint8_t ToPin, uint8_t ExcludePin)
{
pinMode(ExcludePin, INPUT);
pinMode(FromPin, OUTPUT);
pinMode(ToPin, OUTPUT);
bool Readings = MeasureInductance(FromPin, ToPin);
pinMode(ExcludePin, OUTPUT);
pinMode(FromPin, OUTPUT);
pinMode(ToPin, OUTPUT);
return Readings;
}
};