Skip to content

Commit b3a380b

Browse files
authored
Change language specifier
1 parent 3b8cd13 commit b3a380b

File tree

1 file changed

+7
-7
lines changed
  • content/arduino-cloud/01.guides/04.micropython

1 file changed

+7
-7
lines changed

content/arduino-cloud/01.guides/04.micropython/content.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,13 @@ To use variables in Arduino IoT Cloud that are not of a basic type, you can set
222222

223223
On the programming side, you need to import the corresponding class in MicroPython. For the colored light example, you need to import the `ColoredLight` class:
224224

225-
```py
225+
```python
226226
from arduino_iot_cloud import ColoredLight
227227
```
228228

229229
The cloud variable needs then to be registered with the client using that type and the name that you gave it ("light" in our example):
230230

231-
```py
231+
```python
232232
client.register(ColoredLight("light", swi=True, on_write=on_colored_light_changed))
233233
```
234234

@@ -241,15 +241,15 @@ In the callback function for this variable ("on_colored_light_changed") you will
241241

242242
Once you receive these values from the Cloud you will need to convert them to RGB so you can set the RGB LEDs accordingly. For reasons of brevity we won't go into the code for the color conversion, it is provided however in the full example code further down. Also we need to make all three RGB LEDs available in the code so their value can be set:
243243

244-
```py
244+
```python
245245
led_red = Pin("LEDR", Pin.OUT)
246246
led_green = Pin("LEDG", Pin.OUT)
247247
led_blue = Pin("LEDB", Pin.OUT)
248248
```
249249

250250
Then each of the three LEDs' brightness needs to be set so that the resulting color is as desired. This is done using a technique called [PWM](/learn/microcontrollers/analog-output/):
251251

252-
```py
252+
```python
253253
def set_led_brightness(led, brightness):
254254
"""
255255
Sets the brightness (0 - 255) of an LED using PWM.
@@ -267,7 +267,7 @@ def set_led_brightness(led, brightness):
267267

268268
With that defined we can set the corresponding values of the RGBs:
269269

270-
```py
270+
```python
271271
def set_leds_from_rgb(rgb, common_cathode=True):
272272
# For common cathode RGB LEDs, invert the RGB values
273273
# since the LED is on when the pin is low.
@@ -280,7 +280,7 @@ def set_leds_from_rgb(rgb, common_cathode=True):
280280

281281
The missing piece is the callback handler for when the cloud variable changes that was defined when registering the variable:
282282

283-
```py
283+
```python
284284
def on_colored_light_changed(client, light):
285285
# Do nothing if the hue, saturation or brightness is None.
286286
if light.hue is None or light.sat is None or light.bri is None:
@@ -297,7 +297,7 @@ def on_colored_light_changed(client, light):
297297

298298
Here is the complete code to try it out:
299299

300-
```py
300+
```python
301301
# This file is part of the Python Arduino IoT Cloud.
302302
# Any copyright is dedicated to the Public Domain.
303303
# https://creativecommons.org/publicdomain/zero/1.0/

0 commit comments

Comments
 (0)