-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d5d42b4
commit de0f498
Showing
17 changed files
with
1,050 additions
and
788 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#ifndef W_ANALOG_INPUT_H | ||
#define W_ANALOG_INPUT_H | ||
|
||
#include "WInput.h" | ||
|
||
class WAnalog : public WInput { | ||
public: | ||
WAnalog(int analogPin, int minimum = 0, int maximum = 100) : WInput(analogPin, INPUT) { | ||
_minimum = minimum; | ||
_maximum = maximum; | ||
_analogMinimum = 0; | ||
#ifdef ESP8266 | ||
_analogMaximum = 1023; | ||
#elif ESP32 | ||
_analogMaximum = 4095; | ||
#endif | ||
} | ||
|
||
void loop(unsigned long now) { | ||
if ((this->isInitialized()) && (hasProperty())) { | ||
int ain = analogRead(pin()); | ||
ain = constrain(ain, _analogMinimum, _analogMaximum); | ||
ain = map(ain, _minimum, _maximum, _analogMinimum, _analogMaximum); | ||
|
||
switch (property()->type()) { | ||
INTEGER: { | ||
property()->asInt(ain); | ||
break; | ||
} | ||
BYTE: { | ||
property()->asByte(ain); | ||
break; | ||
} | ||
DOUBLE: { | ||
property()->asDouble(ain); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
private: | ||
int _analogMinimum; | ||
int _analogMaximum; | ||
int _minimum; | ||
int _maximum; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.