Driver for HC-SR04 connected to a Microbit
MicrobitUltrasound Class Reference
Class definition for MicroBit Ultrasonic distance sensor. More...
#include <MicrobitUltrasound.h>
Public Member Functions | |
MicrobitUltrasound (PinName triggerPinName, int _triggerPeriod_ms, bool _triggerActiveValue, PinName echoPinName, PinMode echoPinMode, uint16_t id=MICROBIT_ID_ULTRASOUND) | |
Constructor. | |
MicrobitUltrasound (PinName triggerPinName, PinName echoPinName, uint16_t id=MICROBIT_ID_ULTRASOUND) | |
Constructor. | |
~MicrobitUltrasound () | |
Destructor for MicrobitUltrasound, where we deregister this instance from the array of fiber components. | |
void | setEchoPinMode (PinMode echoPinMode) |
Set Echo PinMode. | |
void | setPeriod (int period_ms) |
Set the sample rate at which the micro:bit triggers sensor (in ms). | |
int | getPeriod () |
Get the sample rate at which the micro:bit triggers sensor (in ms). | |
int | start (void) |
Start periodic trigger to sensor. | |
int | stop (void) |
Stop periodic trigger to sensor. | |
int | eventOn (int eventType) |
Enables a particular event for the MicrobitUltrasound. | |
void | fireTrigger (void) |
Send trigger to start measurement in sensor. | |
virtual void | idleTick () |
Periodic callback from MicroBit idle thread. |
Detailed Description
Class definition for MicroBit Ultrasonic distance sensor.
Infers and stores the distance reported by ultrasonic sensor attached to the micro:bit. The library has been tested with sensor HC-SR04
Definition at line 78 of file MicrobitUltrasound.h.
Constructor & Destructor Documentation
MicrobitUltrasound | ( | PinName | triggerPinName, |
int | _triggerPeriod_ms, | ||
bool | _triggerActiveValue, | ||
PinName | echoPinName, | ||
PinMode | echoPinMode, | ||
uint16_t | id = MICROBIT_ID_ULTRASOUND |
||
) |
Constructor.
Class definition for MicroBitPin.
Create new MicrobitUltrasound that reports distance to closest object
- Parameters:
-
triggerPinName Name of the MicroBitPin to be used as trigger. echoPinName Name of the MicroBitPin to be used as response from sensor.
MicrobitUltrasound uSoundSensor(MICROBIT_PIN_P1, 100, true, MICROBIT_PIN_P2, PullUp);
Commonly represents an I/O pin on the edge connector. Constructor. Create new MicrobitUltrasound that reports distance to closest object
- Parameters:
-
triggerPinName Name of the MicroBitPin to be used as trigger. echoPinName Name of the MicroBitPin to be used as response from sensor.
MicrobitUltrasound uSoundSensor(MICROBIT_PIN_P1, 100, true, MICROBIT_PIN_P2, PullUp);
Definition at line 47 of file MicrobitUltrasound.cpp.
MicrobitUltrasound | ( | PinName | triggerPinName, |
PinName | echoPinName, | ||
uint16_t | id = MICROBIT_ID_ULTRASOUND |
||
) |
Constructor.
Create new MicrobitUltrasound that reports distance to closest object
- Parameters:
-
triggerPinName Name of the MicroBitPin to be used as trigger. echoPinName Name of the MicroBitPin to be used as response from sensor.
MicrobitUltrasound uSoundSensor(MICROBIT_PIN_P1, MICROBIT_PIN_P2);
Definition at line 75 of file MicrobitUltrasound.cpp.
~MicrobitUltrasound | ( | ) |
Destructor for MicrobitUltrasound, where we deregister this instance from the array of fiber components.
Destructor for MicrobitUltrasound, where we deregister from the array of fiber components.
Definition at line 93 of file MicrobitUltrasound.cpp.
Member Function Documentation
int eventOn | ( | int | eventType ) |
Enables a particular event for the MicrobitUltrasound.
Enables a particular event for the current module.
- Returns:
- 1 if we're due to take a new trigger, 0 otherwise.
Definition at line 288 of file MicrobitUltrasound.cpp.
void fireTrigger | ( | void | ) |
Send trigger to start measurement in sensor.
This call also will add the class to fiber components to receive one callback only.
- Returns:
- MICROBIT_OK on success.
Definition at line 190 of file MicrobitUltrasound.cpp.
int getPeriod | ( | ) |
Get the sample rate at which the micro:bit triggers sensor (in ms).
- Returns:
- period the requested time between triggers, in milliseconds.
Definition at line 177 of file MicrobitUltrasound.cpp.
void idleTick | ( | ) | [virtual] |
Periodic callback from MicroBit idle thread.
Definition at line 267 of file MicrobitUltrasound.cpp.
void setEchoPinMode | ( | PinMode | echoPinMode ) |
Set Echo PinMode.
Definition at line 101 of file MicrobitUltrasound.cpp.
void setPeriod | ( | int | period_ms ) |
Set the sample rate at which the micro:bit triggers sensor (in ms).
The default sample period is 1 second.
- Parameters:
-
period the requested time between triggers, in milliseconds.
- Note:
- the micro:bit sends triggers in the background.
Definition at line 167 of file MicrobitUltrasound.cpp.
int start | ( | void | ) |
Start periodic trigger to sensor.
This call also will add the class to fiber components for periodic callbacks.
- Returns:
- MICROBIT_OK on success.
Definition at line 208 of file MicrobitUltrasound.cpp.
int stop | ( | void | ) |
Stop periodic trigger to sensor.
- Returns:
- MICROBIT_OK on success.
Definition at line 221 of file MicrobitUltrasound.cpp.
Generated on Tue Jul 12 2022 18:37:37 by 1.7.2