ManualControl

Dependencies:   TPixy-Interface

Fork of MbedOS_Robot_Team by ECE4333 - 2018 - Ahmed & Brandon

ExternalInterruptThread.cpp

Committer:
asobhy
Date:
2018-02-01
Revision:
0:a355e511bc5d
Child:
7:73fd05fe556a

File content as of revision 0:a355e511bc5d:

#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.
}