You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// This is the library for HCSR40 ultrasonic sensor.
16
+
/// This is the library for HCSR40 ultrasonic sensor used to measure distance.
4
17
///
5
-
/// During its work, the sensor will send an ultrasonic signal and receive the reflected signal. You can get a round-trip time. The sound speed in the air is 343m/s. Then you can calculate the distance in-between.
18
+
/// During its work, the sensor will send an ultrasonic signal and
19
+
/// receive the reflected signal. You can get a round-trip time.
20
+
/// The sound speed in the air is 343m/s.
21
+
/// Then you can calculate the distance in-between.
6
22
///
7
-
/// - Attention: Make sure to use the sensor that requires 3.3V, or it might return a wrong value and even do damage to your board.
23
+
/// - Attention: Make sure to use the sensor that requires 3.3V,
24
+
/// or it might return a wrong value and even do damage to your board.
8
25
finalpublicclassHCSR40{
9
-
lettrig:DigitalOut
10
-
letecho:DigitalIn
11
-
lettimeout:Float
26
+
privatelettrig:DigitalOut
27
+
privateletecho:DigitalIn
28
+
privatelettimeout:Float
12
29
13
30
/// Initialize an ultrasonic sensor.
14
-
/// You need to use two digital pins to send and receive signal. Then you set a maximum time to wait for the signal to avoid too long a distance or any unexpected situation.
31
+
/// You need to use two digital pins to send and receive signal.
32
+
/// Then you set a maximum time to wait for the signal to
33
+
/// avoid too long a distance or any unexpected situation.
15
34
/// - Parameters:
16
35
/// - trig: **REQUIRED** A DigitalOut pin used to output a pulse.
17
36
/// - echo: **REQUIRED** A DigitalIn pin used to read the pulse.
18
-
/// - timeout: **OPTIONAL** A preset time to wait for the response. 0.1s by default.
37
+
/// - timeout: **OPTIONAL** A preset time to wait for the response.
This is the library for IS31FL3731 chip. It supports I2C communication. By default, you can use it with a 9x16 LED matrix.
9
-
10
-
The LED matrix has 16 rows (X0 - X15), each row has 9 LEDs (Y0 - Y8). One LED stands for one pixel. The first LED labeled X0 and Y0 is the origin. There are two ways to indicate it: 0 or (0,0). Each LED has 8-bit grayscale, that is, its brightness has 256 levels. 0 is off and 255 is full brightness.
21
+
This is the library for IS31FL3731 chip. It supports I2C communication.
22
+
By default, you can use it with a 9x16 LED matrix.
11
23
12
-
You can also regard the LED matrix as a 9x16 screen and use `MadDisplay` to display text on it.
24
+
The LED matrix has 16 rows (X0 - X15), each row has 9 LEDs (Y0 - Y8).
25
+
One LED stands for one pixel. The first LED labeled X0 and Y0 is the origin.
26
+
There are two ways to indicate it: 0 or (0,0).
27
+
Each LED has 8-bit grayscale, that is, its brightness has 256 levels.
28
+
0 is off and 255 is full brightness.
13
29
14
-
- Attention: If you set all pixels to full brightness, the module will require too much current. So you may need to connect an external power supply instead of the computer's USB port. And if you hear buzzing from it, don't worry, it's because it works quickly to switch LED on and off.
30
+
You can also regard the LED matrix as a 9x16 screen and
31
+
use `MadDisplay` to display text on it.
15
32
33
+
- Attention: If you set all pixels to full brightness, the module will require
34
+
too much current. So you may need to connect an external power supply
35
+
instead of the computer's USB port. And if you hear buzzing from it,
36
+
don't worry, it's because it works quickly to switch LED on and off.
16
37
*/
17
38
18
39
publicfinalclassIS31FL3731{
@@ -40,7 +61,7 @@ public final class IS31FL3731 {
40
61
/**
41
62
Initialize the module to get it ready for lighting.
42
63
- Parameter i2c: **REQUIRED** The I2C interface that the module connects.
43
-
- Parameter address: **OPTIONAL** The address of the module. It has a default value.
64
+
- Parameter address: **OPTIONAL** The address of the module.
44
65
*/
45
66
publicinit(i2c:I2C, address:UInt8=0x74){
46
67
@@ -103,10 +124,12 @@ public final class IS31FL3731 {
103
124
}
104
125
105
126
/**
106
-
Light an LED by telling its number from 0 to 143. The brightness of the LED can range from 0 (off) to 255 (full brightness).
127
+
Light an LED by telling its number from 0 to 143.
128
+
The brightness of the LED can range from 0 (off) to 255 (full brightness).
107
129
108
130
- Parameter number: **REQUIRED** The location of the LED from 0 to 143.
109
-
- Parameter brightness: **REQUIRED** The brightness of the specified LED. By default, the LED is set to full brightness.
131
+
- Parameter brightness: **REQUIRED** The brightness of the specified LED.
@@ -118,11 +141,14 @@ public final class IS31FL3731 {
118
141
/**
119
142
Light an LED by telling its coordinates.
120
143
121
-
You can know the coordinate from the labels printed on the module. The x is from 0 to 15 and y is from 0 to 8. Each LED can have 256 levels of brightness from 0 (off) to 255 (full brightness).
144
+
You can know the coordinate from the labels printed on the module.
145
+
The x is from 0 to 15 and y is from 0 to 8. Each LED can have 256 levels
146
+
of brightness from 0 (off) to 255 (full brightness).
122
147
123
148
- Parameter x: **REQUIRED** The x coordinate of the LED.
124
149
- Parameter y: **REQUIRED** The y coordinate of the LED.
125
-
- Parameter brightness: **REQUIRED** The brightness of the specified LED. By default, the LED is set to full brightness.
150
+
- Parameter brightness: **REQUIRED** The brightness of the specified LED.
@@ -133,16 +159,25 @@ public final class IS31FL3731 {
133
159
}
134
160
135
161
/**
136
-
Set a part of the pixels on the matrix by defining the area. The area is a rectangle determined by a starting point, width and height. Then you can set the pixels to any brightness to get a unique lighting effect.
162
+
Set a part of the pixels on the matrix by defining the area.
163
+
The area is a rectangle determined by a starting point, width and height.
164
+
Then you can set the pixels to any brightness to get a unique
165
+
lighting effect.
137
166
138
-
- Parameter x: **REQUIRED** The horizontal line of the matrix to decide the start point, from 0 to 15.
139
-
- Parameter y: **REQUIRED** The vertical line of the matrix to decide the start point, from 0 to 8.
140
-
- Parameter width: **REQUIRED** The number of pixels in the horizontal direction.
141
-
- Parameter height: **REQUIRED** The number of pixels in the vertical direction.
142
-
- Parameter brightness: **REQUIRED** The brightness level of all the pixels. Each byte stands for the brightness of each pixel
167
+
- Parameter x: **REQUIRED** The horizontal line of the matrix to decide
168
+
the start point, from 0 to 15.
169
+
- Parameter y: **REQUIRED** The vertical line of the matrix to decide
170
+
the start point, from 0 to 8.
171
+
- Parameter width: **REQUIRED** The number of pixels horizontally.
172
+
- Parameter height: **REQUIRED** The number of pixels vertically.
173
+
- Parameter brightness: **REQUIRED** The brightness level of all pixels.
174
+
Each byte stands for the brightness of each pixel.
/// This is the library for the LIS3DH accelerometer. You can use the sensor to measure the accelerations in x, y, and z-axes.
16
+
/// This is the library for the LIS3DH accelerometer.
17
+
/// You can use the sensor to measure the accelerations in x, y, and z-axes.
4
18
///
5
-
/// The acceleration describes the change of velocity with time, usually measured in m/s^2. The sensor measures it by detecting the force. It can sense gravity and measure inertial force caused by movement. They will change the internal capacitance of the sensor, thus change the voltage in the circuit.
19
+
/// The acceleration describes the change of velocity with time,
20
+
/// usually measured in m/s^2. The sensor measures it by detecting the force.
21
+
/// It can sense gravity and measure inertial force caused by movement.
22
+
/// They will change the internal capacitance of the sensor,
23
+
/// thus change the voltage in the circuit.
6
24
///
7
-
/// The sensor supports I2C and SPI protocol. It will give raw readings between -32768 and 32767 (16-bit resolution). The acceleration has direction so you will get positive or negative values. The calculation of acceleration depends on the selected scaling range: ±2, ±4, ±8 or ±16g. The raw reading will be mapped according to the range.
25
+
/// The sensor supports I2C and SPI protocol.
26
+
/// It will give raw readings between -32768 and 32767 (16-bit resolution).
27
+
/// The acceleration has direction so you will get positive or negative values.
28
+
/// The calculation of acceleration depends on the selected scaling range:
29
+
/// ±2, ±4, ±8 or ±16g. The raw reading will be mapped according to the range.
8
30
finalpublicclassLIS3DH{
9
31
10
32
11
-
/// The ranges of the measurement. It will decide how the raw reading is calculated.
33
+
/// The ranges of the measurement.
12
34
publicenumGRange:UInt8{
35
+
/// The acceleration is from -2g to 2g. It is the default setting.
13
36
case g2 =0
37
+
/// The acceleration is from -4g to 4g.
14
38
case g4 =0b0001_0000
39
+
/// The acceleration is from -8g to 8g.
15
40
case g8 =0b0010_0000
41
+
/// The acceleration is from -16g to 16g.
16
42
case g16 =0b0011_0000
17
43
}
18
44
19
45
20
-
/// The supported data rate for the sensor.
46
+
/// The supported data rate for the sensor, 400Hz by default.
21
47
publicenumDataRate:UInt8{
22
48
case powerDown =0
23
49
case Hz1 =0b0001_0000
@@ -59,7 +85,7 @@ final public class LIS3DH {
59
85
/// Initialize the sensor using I2C communication.
60
86
/// - Parameters:
61
87
/// - i2c: **REQUIRED** The I2C interface that the sensor connects.
62
-
/// - address: **OPTIONAL** The device address of the sensor. It has a default value.
88
+
/// - address: **OPTIONAL** The device address of the sensor.
63
89
publicinit(_ i2c:I2C, address:UInt8=0x18){
64
90
self.i2c = i2c
65
91
self.address = address
@@ -77,13 +103,15 @@ final public class LIS3DH {
77
103
}
78
104
79
105
80
-
/// Get the device ID from the sensor. It can be used to test if the sensor is connected.
106
+
/// Get the device ID from the sensor.
107
+
/// It can be used to test if the sensor is connected.
81
108
/// - Returns: The device ID.
82
109
publicfunc getDeviceID()->UInt8{
83
110
returnreadRegister(.WHO_AM_I)
84
111
}
85
112
86
-
/// Set the scaling range of the sensor. The supported ranges are ±2, ±4, ±8 and ±16g.
113
+
/// Set the scaling range of the sensor.
114
+
/// The supported ranges are ±2, ±4, ±8 and ±16g.
87
115
/// - Parameter newRange: The selected `GRange`.
88
116
publicfunc setRange(_ newRange:GRange){
89
117
gRange = newRange
@@ -132,11 +160,13 @@ final public class LIS3DH {
132
160
}
133
161
134
162
135
-
/// Read x, y, z acceleration values represented in g (9.8m/s^2) within the selected range.
163
+
/// Read x, y, z acceleration values represented in g (9.8m/s^2)
164
+
/// within the selected range.
136
165
/// - Returns: 3 float within the selected g range.
0 commit comments