Skip to content

Commit f1dbd78

Browse files
committed
stmhal: Document pyb.Accel() constructor, that it takes time to start.
1 parent f917f06 commit f1dbd78

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

stmhal/accel.c

+15-2
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@
4343
/// \moduleref pyb
4444
/// \class Accel - accelerometer control
4545
///
46-
/// Accel is an object that controls the accelerometer.
46+
/// Accel is an object that controls the accelerometer. Example usage:
4747
///
48-
/// Raw values are between -30 and 30.
48+
/// accel = pyb.Accel()
49+
/// for i in range(10):
50+
/// print(accel.x(), accel.y(), accel.z())
51+
///
52+
/// Raw values are between -32 and 31.
4953

5054
#define MMA_ADDR (0x98)
5155
#define MMA_REG_X (0)
@@ -118,6 +122,15 @@ STATIC pyb_accel_obj_t pyb_accel_obj;
118122

119123
/// \classmethod \constructor()
120124
/// Create and return an accelerometer object.
125+
///
126+
/// Note: if you read accelerometer values immediately after creating this object
127+
/// you will get 0. It takes around 20ms for the first sample to be ready, so,
128+
/// unless you have some other code between creating this object and reading its
129+
/// values, you should put a `pyb.delay(20)` after creating it. For example:
130+
///
131+
/// accel = pyb.Accel()
132+
/// pyb.delay(20)
133+
/// print(accel.x())
121134
STATIC mp_obj_t pyb_accel_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
122135
// check arguments
123136
mp_arg_check_num(n_args, n_kw, 0, 0, false);

0 commit comments

Comments
 (0)