-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
examples/Interrupts/Interrupt_Delayed/Interrupt_Delayed.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,55 @@ | ||
#include <Loom.h> | ||
|
||
// Include configuration | ||
const char* json_config = | ||
#include "config.h" | ||
; | ||
|
||
// In Tools menu, set: | ||
// Internet > Disabled | ||
// Sensors > Enabled | ||
// Radios > Disabled | ||
// Actuators > Disabled | ||
// Max > Disabled | ||
|
||
using namespace Loom; | ||
|
||
Loom::Manager Feather{}; | ||
|
||
// Can be whatever pin you want | ||
const int PIN_NUM = 11; | ||
|
||
// This is not actually called immediately upon an interrupt being generated | ||
// It is called on next iteration of loop() | ||
// Thus, this function can be as complicated as you wish since it is not called directly upon interrupt trigger | ||
void handle_ISR() { | ||
detachInterrupt(PIN_NUM); | ||
|
||
LPrintln("Interrupt triggered!"); | ||
LPrintln("Waiting for interrupt to trigger..."); | ||
|
||
// If using a button/switch, simple solution to bounce (just pause a bit for switch to settle) | ||
delay(5); | ||
|
||
// Reconnect interrupt since it was previously detached | ||
getInterruptManager(Feather).reconnect_interrupt(PIN_NUM); | ||
} | ||
|
||
void setup() | ||
{ | ||
Feather.begin_serial(true); | ||
Feather.parse_config(json_config); | ||
Feather.print_config(); | ||
|
||
// Creates a delayed interrupt for specified pin number, sets it as an internal pullup, and generates an interrupt on a LOW signal | ||
getInterruptManager(Feather).register_ISR(PIN_NUM, handle_ISR, LOW, ISR_Type::CHECK_FLAG); | ||
|
||
LPrintln("\n ** Setup Complete ** "); | ||
LPrintln("Waiting for interrupt to trigger..."); | ||
} | ||
|
||
void loop() | ||
{ | ||
// Runs the ISR for any interrupts that may have been triggered since last call | ||
getInterruptManager(Feather).run_pending_ISRs(); | ||
} |
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 @@ | ||
"{\ | ||
'general':\ | ||
{\ | ||
'name':'Device',\ | ||
'instance':1,\ | ||
'interval':500,\ | ||
'print_verbosity':2\ | ||
},\ | ||
'components':[\ | ||
{\ | ||
'name':'InterruptManager',\ | ||
'params':[0]\ | ||
}\ | ||
]\ | ||
}" |
56 changes: 56 additions & 0 deletions
56
examples/Interrupts/Interrupt_Immediate/Interrupt_Immediate.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,56 @@ | ||
#include <Loom.h> | ||
|
||
// Include configuration | ||
const char* json_config = | ||
#include "config.h" | ||
; | ||
|
||
// In Tools menu, set: | ||
// Internet > Disabled | ||
// Sensors > Enabled | ||
// Radios > Disabled | ||
// Actuators > Disabled | ||
// Max > Disabled | ||
|
||
using namespace Loom; | ||
|
||
Loom::Manager Feather{}; | ||
|
||
// Can be whatever pin you want | ||
const int PIN_NUM = 11; | ||
|
||
// Typically a flag is set in an ISR since ISR's should be quick and concise | ||
// Should be volatile since the variable can be changed outside normal program flow | ||
volatile bool flag = false; | ||
|
||
// Typical Interrupt Service Routine | ||
void handle_ISR() { | ||
detachInterrupt(PIN_NUM); | ||
flag = true; | ||
} | ||
|
||
void setup() | ||
{ | ||
Feather.begin_serial(true); | ||
Feather.parse_config(json_config); | ||
Feather.print_config(); | ||
|
||
// Creates an immediate interrupt for specified pin number, sets it as an internal pullup, and generates an interrupt on a LOW signal | ||
getInterruptManager(Feather).register_ISR(PIN_NUM, handle_ISR, LOW, ISR_Type::IMMEDIATE); | ||
|
||
LPrintln("\n ** Setup Complete ** "); | ||
} | ||
|
||
void loop() { | ||
// Reconnect interrupt since it is disabled in ISR | ||
getInterruptManager(Feather).reconnect_interrupt(PIN_NUM); | ||
LPrintln("Waiting for interrupt to trigger..."); | ||
|
||
// Set flag to false and wait until the ISR sets it to true | ||
flag = false; | ||
while(!flag); | ||
LPrintln("Interrupt triggered!"); | ||
|
||
// If using a button/switch, simple solution to bounce (just pause a bit for switch to settle) | ||
delay(5); | ||
} |
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 @@ | ||
"{\ | ||
'general':\ | ||
{\ | ||
'name':'Device',\ | ||
'instance':1,\ | ||
'interval':500,\ | ||
'print_verbosity':2\ | ||
},\ | ||
'components':[\ | ||
{\ | ||
'name':'InterruptManager',\ | ||
'params':[0]\ | ||
}\ | ||
]\ | ||
}" |