-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathA1301.h
131 lines (98 loc) · 2.29 KB
/
A1301.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#pragma once
//
// FILE: A1301.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.3
// DATE: 2010-07-22
// PURPOSE: Arduino library for A1301 A1302 magnetometer.
// URL: https://github.com/RobTillaart/A1301
// always check datasheet.
// PIN A1301
// ===============
// 1 GND
// 2 DATA
// 3 VDD +5V
#include "Arduino.h"
#define A1301_LIB_VERSION (F("0.2.3"))
class HALL
{
public:
HALL(uint8_t pin);
// ADC parameters
void begin(float voltage, uint16_t steps);
// midpoint depends on ADC.
void setMidPoint(float midPoint);
float autoMidPoint(uint8_t times = 100);
float getMidPoint();
// to override default sensitivity
void setSensitivity(float sensitivity);
float getSensitivity();
// READ
// times > 1 ==> more stable read / averaging.
// uses internal ADC
float raw(uint8_t times = 1); // returns raw ADC
float read(uint8_t times = 1); // returns Gauss
// for external ADC
float readExt(float raw);
// ANALYSE
bool isNull();
bool isNorth();
bool isSouth();
bool isRising();
bool isFalling();
float lastGauss();
float prevGauss();
float deltaGauss();
float angle(); // == atan2(prevGauss, lastGauss);
float determineNoise(uint8_t times = 2); // in Gauss
// CONVERTERs
float Tesla(float Gauss);
float mTesla(float Gauss);
float uTesla(float Gauss);
// SATURATION LEVEL = EXPERIMENTAL
// manual override default maxGauss
void setMaxGauss(float maxGauss);
float getMaxGauss();
bool isSaturated();
float saturationLevel();
protected:
uint8_t _pin;
float _midPoint;
float _prevGauss;
float _lastGauss;
float _GaussmV; // == 1.0 / mVGauss
float _mVStep;
uint16_t _maxADC;
// Experimental
float _maxGauss;
};
////////////////////////////////////////////////////
//
// DERIVED CLASSES
//
class A1301 : public HALL
{
public:
A1301(uint8_t pin);
};
class A1302 : public HALL
{
public:
A1302(uint8_t pin);
};
class A1324 : public HALL
{
public:
A1324(uint8_t pin);
};
class A1325 : public HALL
{
public:
A1325(uint8_t pin);
};
class A1326 : public HALL
{
public:
A1326(uint8_t pin);
};
// -- END OF FILE --