-
Notifications
You must be signed in to change notification settings - Fork 17
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
Phil Bowles
committed
Feb 20, 2020
1 parent
b929f39
commit 814494c
Showing
15 changed files
with
222 additions
and
43 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
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
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
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
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
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,64 @@ | ||
#include<H4Plugins.h> | ||
H4_USE_PLUGINS | ||
/* | ||
My major testing devices were nodeMCU which has builtin button on GPIO0 which is ACTIVE_LOW | ||
and STM32NUCLEO-F429ZI whuch has a user button that is ACTIVE_HIGH | ||
You will probably need to adjust these values for you own device | ||
*/ | ||
#ifdef ARDUINO_ARCH_STM32 | ||
#define UB_ACTIVE ACTIVE_HIGH | ||
#define UL_ACTIVE ACTIVE_HIGH | ||
#else | ||
#define USER_BTN 0 | ||
#define UB_ACTIVE ACTIVE_LOW | ||
#define UL_ACTIVE ACTIVE_LOW | ||
#endif | ||
/* | ||
ALL GPIO strategies are derived from H4GPIOPin: the following members are available | ||
inside ALL GPIO pin callbacks, once you have a valid pointer for the pin type using | ||
H4GM_PIN( type ) with specific underlying type Raw needs H4GM_PIN(Raw); | ||
uint8_t pin=0; // GPIO hardware pin number | ||
uint8_t gpioType=0; // INPUT, INPUT_PULLUP, OUTPUT etc | ||
H4GM_STYLE style; // Strategy: Raw, debounced, retriggering etc | ||
uint8_t sense=0; // active HIGH or LOW | ||
unsigned long Tevt=0; // uS time of last event | ||
int state=0; // 32 wide as it holds analog value as well as digital 0/1 | ||
// and not uint because encoder returns -1 or +1 | ||
uint32_t delta=0; // uS since last change | ||
uint32_t rate=0; // instantaenous rate cps | ||
uint32_t Rpeak=0; // peak rate | ||
uint32_t cps=0; // sigma changes/sec (used internally, frequently re-set) | ||
uint32_t cMax=UINT_MAX; // max permitted cps (see "throttling"); | ||
uint32_t nEvents=UINT_MAX; // sigma "Events" (meaning depends on inheriting strategy) | ||
Additional members for AnalogThreshold: | ||
limit the threshold value: below this figure = 0, above it = 1 | ||
AnalogThreshold has its state checked periodically, usually with a large value, e.g. minutes. It is used | ||
when you do *not* want to react quickly. A good example is a light sensor at dusk: you want lights | ||
to come on when it is "dark". As the light fades the sensor will "flutter" rapidly for quite a long | ||
time before settling to its "dark" value. Only *then* do you want to switch the lights. | ||
Each time it is polled, it will compare the raw analog value with limit and return 1 ig greater, else 0 | ||
analog value. | ||
*/ | ||
|
||
H4 h4(115200); //auto-start Serial @ 115200, Q size=20 | ||
H4P_GPIOManager h4gm; | ||
|
||
#define U_POLL_FREQ 5000 | ||
#define U_LIMIT 100 | ||
|
||
void h4setup() { // H4 constructor starts Serial | ||
Serial.println("H4P_GPIOManager AnalogThreshold Example v"H4P_VERSION); | ||
|
||
h4gm.AnalogThreshold(A0,U_POLL_FREQ,U_LIMIT,[](H4GPIOPin* ptr){ | ||
H4GM_PIN(AnalogThreshold); // Create the correct pointer type in 'pin' | ||
Serial.print("T=");Serial.print(millis()); | ||
Serial.print(" AnalogThreshold ");Serial.print(pin->pin); | ||
Serial.print(" AnalogThreshold IS ");Serial.println(pin->logicalRead()); | ||
}); | ||
} |
15 changes: 15 additions & 0 deletions
15
examples/H4GM_AnalogThresholdThing/H4GM_AnalogThresholdThing.ino
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,15 @@ | ||
#include<H4Plugins.h> | ||
H4_USE_PLUGINS | ||
|
||
#define F_POLL 5000 | ||
|
||
H4 h4(115200); | ||
H4P_SerialCmd h4sc; | ||
H4P_GPIOManager h4gm; | ||
|
||
H4P_BinarySwitch h4onof(LED_BUILTIN,ACTIVE_LOW,OFF); | ||
|
||
void h4setup(){ | ||
h4gm.AnalogThresholdThing(LIGHT,F_POLL,100,H4GM_GREATER,&h4onof); // On if A0 > 100 | ||
//h4gm.AnalogThresholdThing(LIGHT,F_POLL,100,H4GM_LESS,&h4onof); // On if A0 < 100 | ||
} |
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
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
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,31 @@ | ||
#include<H4Plugins.h> | ||
H4_USE_PLUGINS | ||
|
||
#define LED_RED D6 | ||
#define LED_YELLOW D7 | ||
#define LED_GREEN D8 | ||
|
||
#define MOTION D1 | ||
#define LIGHT A0 | ||
|
||
#define F_POLL 5000 | ||
|
||
H4 h4(115200); | ||
H4P_SerialCmd h4sc; | ||
H4P_GPIOManager h4gm; | ||
//H4P_WiFi h4wifi("XXXXXXXX","XXXXXXXX","h4plugins"); | ||
//H4P_MQTT h4mqtt("192.168.1.4",1883); | ||
//H4P_AsyncWebServer h4asws("admin","admin"); | ||
//H4P_UPNPSwitch h4upnp("Demo Switch",RELAY_BUILTIN,ACTIVE_HIGH,OFF); | ||
H4P_BinarySwitch h4onof(LED_RED,ACTIVE_HIGH,OFF); | ||
H4P_FlasherController h4fc; | ||
H4P_ThreeFunctionButton h43fb(&h4onof,15,BUTTON_BUILTIN,INPUT,ACTIVE_LOW,LED_BUILTIN,ACTIVE_LOW); | ||
|
||
void h4setup(){ | ||
h4gm.RetriggeringThing(MOTION,INPUT,ACTIVE_HIGH,10000,&h4onof); // 10sec motion timeout | ||
h4gm.Polled(LIGHT,INPUT,ACTIVE_HIGH,F_POLL,true,[](H4GPIOPin* ptr){ | ||
H4GM_PIN(Polled); | ||
Serial.printf("POLLED = %d\n",pin->state); | ||
h4onof.turn(pin->state < 60 ? 1:0); | ||
}); // door alarm | ||
} |
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.