ObjectFollower
Dependencies: TPixy-Interface
Fork of PlayBack by
Diff: ExternalInterruptThread.cpp
- Revision:
- 0:a355e511bc5d
- Child:
- 7:73fd05fe556a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ExternalInterruptThread.cpp Thu Feb 01 03:58:00 2018 +0000 @@ -0,0 +1,36 @@ +#include "mbed.h" + +void ExtInterruptISR(void); +void ExtInterruptThread(void const *argument); + +osThreadId ExtInterruptId; + +osThreadDef(ExtInterruptThread, osPriorityHigh, 1024); // Declare ExtInterruptThread as a thread/process + +InterruptIn Bumper(p8); // External interrupt pin declared as Bumper + +DigitalOut led2(LED2); + + +void ExternalInterruptThreadInit() +{ + Bumper.rise(&ExtInterruptISR); // Attach the address of the interrupt handler to the rising edge of Bumper + ExtInterruptId = osThreadCreate(osThread(ExtInterruptThread), NULL); +} + + +// ******** External Interrupt Thread ******** +void ExtInterruptThread(void const *argument) +{ + while (true) { + osSignalWait(0x01, osWaitForever); // Go to sleep until signal, SignalExtCollision, is received + led2 = !led2; + } +} + + +// ******** External Interrupt Handler ******** +void ExtInterruptISR(void) +{ + osSignalSet(ExtInterruptId,0x01); // Send signal to the thread with ID, ExtInterruptId, i.e., ExtInterruptThread. +}