Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Julián's review
  • Loading branch information
canchebagur committed Jul 3, 2023
commit 95a822c85492bb39dbe16849e4f6660df53e7e11
Original file line number Diff line number Diff line change
Expand Up @@ -1488,43 +1488,74 @@ Your dashboard should see like the following:
Go back to your **Things** and open the "Thing" you just created. In the "Thing" setup page, navigate into **Sketch** where you should see the online editor.


In the generated sketch, you just need to define the `led` pin as an output:
In the generated sketch, define `LED_BUILTIN` pin as an output in the `setup()` function:

```arduino
// LED_BUILTIN macro access the onboard green LED
pinMode(LED_BUILTIN, OUTPUT);
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);

// LED_BUILTIN macro access the onboard green LED
pinMode(LED_BUILTIN, OUTPUT);

// Defined in thingProperties.h
initProperties();

// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);

/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
```

In the `onLedChange()` function, you just need to set the LED state with the `led` variable.

```arduino
// led variable synced with the Arduino IoT Cloud dashboard
digitalWrite(LED_BUILTIN, led);
/*
Since Led is READ_WRITE variable, onLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLedChange() {
digitalWrite(LED_BUILTIN, led);
}
```

The full example code can be found below:

```arduino
/*
Sketch generated by the Arduino IoT Cloud
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/5667878a-bf88-483b-a17e-6600b63e7da8

Arduino IoT Cloud Variables description

The following variables are automatically generated and updated when changes are made to the Thing

bool led;

Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);

// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);

// LED_BUILTIN macro access the onboard green LED
pinMode(LED_BUILTIN, OUTPUT);

// Defined in thingProperties.h
initProperties();

Expand All @@ -1544,16 +1575,15 @@ void setup() {

void loop() {
ArduinoCloud.update();
// Your code here
}


/*
Since Led is READ_WRITE variable, onLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLedChange() {
// led variable synced with the Arduino IoT Cloud dashboard
digitalWrite(LED_BUILTIN,led);
digitalWrite(LED_BUILTIN, led);
}
```

Expand Down