Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed-dev-bin nRF51822
MicroBitValue Class Reference
Class definition for MicroBit Value. More...
#include <MicroBitValue.h>
Inherits MicroBitComponent.
Public Member Functions | |
| MicroBitValue (MicroBitStorage &_storage, uint16_t id=MICROBIT_ID_VALUE) | |
| Constructor. | |
| MicroBitValue (uint16_t id=MICROBIT_ID_VALUE) | |
| Constructor. | |
| int | getV () |
| Reads the value of the V integer. | |
| void | setV (int v) |
| Set the value of the V integer. | |
| int | updateSample () |
| Updates the local sample, only if the compass indicates that data is stale. | |
| virtual void | idleTick () |
| Periodic callback from MicroBit idle thread. | |
| ~MicroBitValue () | |
| Destructor for MicroBitCompass, where we deregister this instance from the array of fiber components. | |
| virtual void | systemTick () |
| The system timer will call this member function once the component has been added to the array of system components using system_timer_add_component. | |
Detailed Description
Class definition for MicroBit Value.
Represents an implementation of shared value. Also includes basic caching.
Definition at line 70 of file MicroBitValue.h.
Constructor & Destructor Documentation
| MicroBitValue | ( | MicroBitStorage & | _storage, |
| uint16_t | id = MICROBIT_ID_VALUE |
||
| ) |
Constructor.
Create a software representation of an e-value.
- Parameters:
-
_storage an instance of MicroBitStorage, used to persist calibration data across resets. id the ID of the new MicroBitCompass object. Defaults to MICROBIT_ID_VALUE.
MicroBitStorage storage; MicroBitValue uBitValue(storage);
Create a software representation of an e-compass.
- Parameters:
-
_i2c an instance of i2c, which the compass is accessible from. _storage an instance of MicroBitStorage, used to persist calibration data across resets. address the default address for the compass register on the i2c bus. Defaults to MAG3110_DEFAULT_ADDR. id the ID of the new MicroBitCompass object. Defaults to MAG3110_DEFAULT_ADDR.
MicroBitI2C i2c(I2C_SDA0, I2C_SCL0); MicroBitStorage storage; MicroBitCompass compass(i2c, storage);
Definition at line 91 of file MicroBitValue.cpp.
| MicroBitValue | ( | uint16_t | id = MICROBIT_ID_VALUE ) |
Constructor.
Create a software representation of an e-value.
- Parameters:
-
id the ID of the new MicroBitCompass object. Defaults to MICROBIT_ID_VALUE.
MicroBitI2C i2c(I2C_SDA0, I2C_SCL0); MicroBitCompass compass(i2c);
Create a software representation of an e-compass.
- Parameters:
-
_i2c an instance of i2c, which the compass is accessible from. address the default address for the compass register on the i2c bus. Defaults to MAG3110_DEFAULT_ADDR. id the ID of the new MicroBitCompass object. Defaults to MAG3110_DEFAULT_ADDR.
MicroBitI2C i2c(I2C_SDA0, I2C_SCL0); MicroBitCompass compass(i2c);
Definition at line 114 of file MicroBitValue.cpp.
| ~MicroBitValue | ( | ) |
Destructor for MicroBitCompass, where we deregister this instance from the array of fiber components.
Definition at line 185 of file MicroBitValue.cpp.
Member Function Documentation
| int getV | ( | ) |
Reads the value of the V integer.
Reads the currently configured sample rate of the compass.
- Returns:
- The value V.
value.getV();
- Returns:
- The time between samples, in milliseconds.
Definition at line 178 of file MicroBitValue.cpp.
| void idleTick | ( | ) | [virtual] |
Periodic callback from MicroBit idle thread.
Calls updateSample().
Reimplemented from MicroBitComponent.
Definition at line 148 of file MicroBitValue.cpp.
| void setV | ( | int | v ) |
Set the value of the V integer.
Attempts to set the sample rate of the compass to the specified value (in ms).
- Parameters:
-
The value V.
value.setV(v);
- Parameters:
-
period the requested time between samples, in milliseconds.
- Returns:
- MICROBIT_OK or MICROBIT_I2C_ERROR if the magnetometer could not be updated.
// sample rate is now 20 ms.
compass.setPeriod(20);
- Note:
- The requested rate may not be possible on the hardware. In this case, the nearest lower rate is chosen.
Definition at line 168 of file MicroBitValue.cpp.
| virtual void systemTick | ( | ) | [virtual, inherited] |
The system timer will call this member function once the component has been added to the array of system components using system_timer_add_component.
This callback will be in interrupt context.
Reimplemented in MicroBitSystemTimerCallback, MicroBitButton, and MicroBitDisplay.
Definition at line 127 of file MicroBitComponent.h.
| int updateSample | ( | ) |
Updates the local sample, only if the compass indicates that data is stale.
- Note:
- Can be used to trigger manual updates, if the device is running without a scheduler. Also called internally by getV() member functions.
- Can be used to trigger manual updates, if the device is running without a scheduler. Also called internally by all get[X,Y,Z]() member functions.
Adds the compass to idle, if it hasn't been added already. This is an optimisation so that the compass is only added on first 'use'.
Definition at line 128 of file MicroBitValue.cpp.
Generated on Fri Nov 4 2022 18:32:47 by
1.7.2