Koadro honetan ikus dezakezu liburutegia kargatu ondoren Arduino MKR Wifi 1010 plakara bidaliko dugun programa:
/*
Sketch generated by the Arduino IoT Cloud Thing "p06" https://create.arduino.cc/cloud/things/29e6694a-f72d-4d82-961d-0fcc367b9205
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float iluminacion;
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" #include <Wire.h> #include <BH1750.h>
BH1750 lightMeter;
|
void setup() {
// Hasieratu seriea eta itxaron ataka ireki arte:
// Hasieratu I2C busa (BH1750 liburutegiak ez du hau automatikoki egiten)
// sentsore konexioaren proba
Serial.begin(9600); Wire.begin(); lightMeter.begin(); lightMeter.configure(BH1750::CONTINUOUS_HIGH_RES_MODE); // edo beste modiren bat. Serial.println(F ("BH1750 Test"); Serial.println(F("BH1750 Konektatuta"));
// Atzerapen honek serieko monitore baten zain egoteko aukera ematen du hura blokeatu gabe, aurkitu ezean.
delay(1500);
// thingProperties-en definitua.h
initProperties();
// Konektatu Arduino IoT Cloud-era
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(); }
|
void loop() { ArduinoCloud.update();
// Hemen zure kodea
// Arduino Cloud plataformarako konexioa probatu
if (ArduinoCloud.connected() == 0) { // Ez dago konexiorik Serial.println("Ez dago konexiorik Arduino Cloud plataformarekin"); Serial.println(); digitalWrite(LED_BUILTIN, LOW);
} else { // Konexiorik badago Serial.println("--------------------------"); Serial.println("Arduino Cloud plataformarekin konexiorik badago");
digitalWrite(LED_BUILTIN, HIGH); }
// intentsitatea lux-tan neurtzea
float lux = lightMeter.readLightLevel();
Serial.println(); Serial.print("Medición (lux): "); Serial.print(lux); Serial.println(" "); delay(1000);
}
|