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
Copy file name to clipboardExpand all lines: content/hardware/06.nicla/boards/nicla-sense-me/tutorials/cheat-sheet/cheat-sheet.md
+27-12Lines changed: 27 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -127,17 +127,13 @@ The Nicla System header is required to use the RGB LED.
127
127
#include "Nicla_System.h"
128
128
```
129
129
130
-
Since the functions are scoped under a specific name called "nicla", you can use the following statement to have convenient access without repeating explicitly the namespace before every function call.
131
-
132
-
```cpp
133
-
usingnamespacenicla;
134
-
```
130
+
Since the functions are scoped under a specific Class name called "nicla", you need to explicitly write it before each statement.
135
131
136
132
The LEDs need to be started along with the Nicla inside `void setup()`:
137
133
138
134
```arduino
139
-
begin();
140
-
leds.begin();
135
+
nicla::begin();
136
+
nicla::leds.begin();
141
137
```
142
138
143
139
The LED can be set to the desired RGB value using red, green and blue components or by using one of the following predefined colors:
@@ -153,17 +149,17 @@ To set the LED to a predefined color (e.g. green or blue):
153
149
154
150
```arduino
155
151
void loop() {
156
-
leds.setColor(green);
152
+
nicla::leds.setColor(green);
157
153
delay(1000);
158
-
leds.setColor(blue);
154
+
nicla::leds.setColor(blue);
159
155
delay(1000);
160
156
}
161
157
```
162
158
163
159
To turn the LED off:
164
160
165
161
```arduino
166
-
leds.setColor(off);
162
+
nicla::leds.setColor(off);
167
163
```
168
164
169
165
You can also choose a value between 255 - 0 for each color component to set a custom color:
@@ -174,13 +170,32 @@ void loop() {
174
170
int green = 72;
175
171
int blue = 122;
176
172
177
-
leds.setColor(red, green, blue);
173
+
nicla::leds.setColor(red, green, blue);
174
+
delay(1000);
175
+
nicla::leds.setColor(off);
176
+
delay(1000);
177
+
}
178
+
```
179
+
180
+
This is a complete example code to blink the built-in I2C LED:
181
+
182
+
```arduino
183
+
#include "Nicla_System.h"
184
+
185
+
void setup() {
186
+
nicla::begin();
187
+
nicla::leds.begin();
188
+
}
189
+
190
+
void loop() {
191
+
nicla::leds.setColor(red);
178
192
delay(1000);
179
-
leds.setColor(off);
193
+
nicla::leds.setColor(off);
180
194
delay(1000);
181
195
}
182
196
```
183
197
198
+
184
199
## Sensors
185
200
186
201
There are three ways to read from the on-board sensors:
0 commit comments