2022-12-02 04:37:37 -05:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: A1301.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2023-01-03 14:01:29 -05:00
|
|
|
// VERSION: 0.1.2
|
2022-12-02 04:37:37 -05:00
|
|
|
// DATE: 2010-07-22
|
|
|
|
// PURPOSE: Arduino library for A1301 A1302 magnetometer.
|
|
|
|
|
|
|
|
// always check datasheet.
|
|
|
|
// PIN A1301
|
|
|
|
// ===============
|
|
|
|
// 1 GND
|
|
|
|
// 2 DATA
|
|
|
|
// 3 VDD +5V
|
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
2023-01-03 14:01:29 -05:00
|
|
|
#define A1301_LIB_VERSION (F("0.1.2"))
|
2022-12-02 04:37:37 -05:00
|
|
|
|
|
|
|
|
|
|
|
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 getMidPoint();
|
2022-12-02 06:52:49 -05:00
|
|
|
// to override default sensitivity
|
2022-12-02 04:37:37 -05:00
|
|
|
void setSensitivity(float sensitivity);
|
|
|
|
float getSensitivity();
|
|
|
|
|
|
|
|
// READ
|
|
|
|
// times > 1 ==> more stable read / averaging.
|
|
|
|
// uses internal ADC
|
2023-01-03 14:01:29 -05:00
|
|
|
float raw(uint8_t times = 1); // returns raw ADC
|
|
|
|
float read(uint8_t times = 1); // returns Gauss
|
2022-12-02 04:37:37 -05:00
|
|
|
// for external ADC
|
|
|
|
float readExt(float raw);
|
|
|
|
|
|
|
|
// ANALYSE
|
2022-12-02 06:52:49 -05:00
|
|
|
bool isNorth();
|
|
|
|
bool isSouth();
|
2022-12-02 04:37:37 -05:00
|
|
|
float lastGauss();
|
|
|
|
float prevGauss();
|
2022-12-02 06:52:49 -05:00
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
// CONVERTERs
|
|
|
|
float Tesla(float Gauss);
|
|
|
|
float mTesla(float Gauss);
|
|
|
|
float uTesla(float Gauss);
|
|
|
|
|
2022-12-02 06:52:49 -05:00
|
|
|
// EXPERIMENTAL
|
|
|
|
// manual override default maxGauss
|
|
|
|
void setMaxGauss(uint16_t maxGauss);
|
|
|
|
float getMaxGauss();
|
|
|
|
bool isSaturated();
|
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
|
|
|
|
protected:
|
2022-12-02 06:52:49 -05:00
|
|
|
uint8_t _pin = 0;
|
|
|
|
float _midPoint = 512;
|
|
|
|
float _prevGauss = 0;
|
|
|
|
float _lastGauss = 0;
|
|
|
|
float _mVGauss = 2.5;
|
|
|
|
float _mVStep = 5000.0 / 1023;
|
|
|
|
uint16_t _maxADC = 1023;
|
|
|
|
|
|
|
|
// Experimental
|
|
|
|
float _maxGauss = 500;
|
2022-12-02 04:37:37 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// DERIVED
|
|
|
|
//
|
|
|
|
class A1301 : public HALL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
A1301(uint8_t pin);
|
|
|
|
};
|
|
|
|
|
|
|
|
class A1302 : public HALL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
A1302(uint8_t pin);
|
|
|
|
};
|
|
|
|
|
2022-12-02 06:52:49 -05:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2022-12-02 04:37:37 -05:00
|
|
|
|
|
|
|
// -- END OF FILE --
|
|
|
|
|