-
Notifications
You must be signed in to change notification settings - Fork 2
DigitalService
Daniel Johnson edited this page Jul 9, 2021
·
4 revisions
The DigitalService is a basic hardware abstraction to Read and Write to digital pins as well as attach interrupts. All functions are passed down to the underlying abstraction. Internal pullup settings should be setup in the abstraction based on the hardware implementation.
Initializes a pin in the selected direction, either In or Out. Configuring the pin as In will set the pin as a high impedance input.
Returns the value of the pin. High = true, Low = false.
Writes a value of either High (true) or Low (false) to the pin.
Attaches an interrupt to any changing event on the pin. Perform a ReadPin to check the state. Calling this function with a new callBack will overwrite any existing callBack.
Detach any interrupt from the pin.
IDigitalService *_digitalService;
void buttonInterrupt()
{
// set LED pin to the state of PA0
_digitalService->WritePin(45, _digitalService->ReadPin(0)); //PC13 = PA0
} // Initialize LED pin
_digitalService->InitPin(45, PinDirection::Out); //PC13 as Output
// Initialize button pin
_digitalService->InitPin(0, PinDirection::In); //PA0 as Input
// Setup interrupt callback
_digitalService->AttachInterrupt(0, &buttonInterrupt); //PA0