Skip to content

Commit 8b8914d

Browse files
author
Main Push Robot
committed
Committing dev changes
1 parent 2375ef5 commit 8b8914d

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

examples/analogRead/analogRead.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
***************************************************/
1212

1313
#include "Hall-Effect-SOLDERED.h"
14-
#define HALL_EFFECT_PIN 2
14+
#define HALL_EFFECT_PIN A0
1515

1616
// For this example, connect the Hall Effect Sensor to your Dasduino board as such:
1717
// VCC to VCC on Dasduino
18-
// OUT to Pin HALL_EFFECT_PIN (can be changed according to your board, here it's A3)
18+
// OUT to Pin HALL_EFFECT_PIN (can be changed according to your board)
1919
// GND to GND
2020

2121
// To change the reading, place a magnet in front of the sensor

src/Hall-Effect-Analog-SOLDERED.cpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ HallEffect_Analog::HallEffect_Analog(int _pin)
2828
* @brief Reads hall effect sensor value
2929
*
3030
* @return Returns a unit16_4 sensor reading value.
31-
*
32-
* @note For no magnet, the value will be around the middle of your analogRead range, which depends
33-
* on your board. When a positive or negative magnet field is detected it will increase or decrease accordingly until it
34-
* reaches the maximum or minimum.
31+
*
3532
*/
3633
uint16_t HallEffect_Analog::getReading()
3734
{
38-
return analogRead(pin);
35+
#ifdef ESP32
36+
uint32_t value = analogReadMilliVolts(pin);
37+
return map(value, 142, 3166, 0, 1024);
38+
#else
39+
return analogRead(pin);
40+
#endif
3941
}
4042

4143
/**
@@ -48,24 +50,6 @@ uint16_t HallEffect_Analog::getReading()
4850
*/
4951
float HallEffect_Analog::getMilliTeslas()
5052
{
51-
5253
float value = float(getReading());
53-
54-
#ifdef ESP32
55-
// For Dasduino ConnectPlus
56-
// Mapping values to correct ones
57-
float milliTeslas;
58-
if (value >= 2686.0)
59-
{
60-
milliTeslas = (value - 2686.0) * (20.35 - 0.00) / (4096.00 - 2686.0) + 0.00;
61-
}
62-
else
63-
{
64-
milliTeslas = (value - 0.00) * (0.00 - (-20.35)) / (2686.0 - 0.00) - 20.35;
65-
}
66-
67-
return milliTeslas;
68-
#else
6954
return 20.47 * (10 * (value / 1023.0) / 5.0 - 1);
70-
#endif
7155
}

0 commit comments

Comments
 (0)