Ho un problema con la funzione "Switch" che utilizzo sul Cloud di Arduino con un NANO33 IoT.
Non riesco a farlo funzionare.
Lo sketch è il seguente:
#include "arduino_secrets.h"
/************************ ****************************************************
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/08b27dbe-a5e2-4b6d-b9b4-647b5227a6ce
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int counter;
CloudSchedule scheduler_test;
bool light;
CloudTime time_read;
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.
Modifica: Introdotto LED_BUILTIN per verifica raggiungimento massimo erogazioni crocchette
********************************************************************************************/
#include "thingProperties.h"
#include <RTCZero.h>
bool toggle;
int LED1;
int LED2;
int LED3;
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);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
counter = 0; // erogazioni crocchette
light = false;
pinMode(LED_BUILTIN, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
}
void loop() {
ArduinoCloud.update();
if(scheduler_test.isActive()) {
light = true;
digitalWrite(LED_BUILTIN, HIGH);
if(toggle) {
counter = ++counter;
toggle = false;
}
} else {
light = false;
digitalWrite(LED_BUILTIN, LOW);
toggle = true;
}
if(ArduinoCloud.connected()) {
time_read = ArduinoCloud.getLocalTime();
}
switch (counter) {
case 3:
digitalWrite(LED1, HIGH);
break;
case 5:
digitalWrite(LED2, HIGH);
break;
case 7:
digitalWrite(LED3, HIGH);
break;
default:
break;
}
}
void onSchedulerTestChange() {
// Aggiungere qui il proprio codice per agire sulla modifica di SchedulerTest
}
/*
Since Counter is READ_WRITE variable, onCounterChange() is
executed every time a new value is received from IoT Cloud.
*/
void onCounterChange() {
// Add your code here to act upon Counter change
}
/*
Since Light is READ_WRITE variable, onLightChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLightChange() {
// Add your code here to act upon Light change
}
il file delle proprietà è questo:
// Code generated by Arduino IoT Cloud, DO NOT EDIT.
#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
const char SSID[] = SECRET_SSID; // Network SSID (name)
const char PASS[] = SECRET_OPTIONAL_PASS; // Network password (use for WPA, or use as key for WEP)
void onCounterChange();
void onSchedulerTestChange();
void onLightChange();
int counter;
CloudSchedule scheduler_test;
bool light;
CloudTime time_read;
void initProperties(){
ArduinoCloud.addProperty(counter, READWRITE, ON_CHANGE, onCounterChange);
ArduinoCloud.addProperty(scheduler_test, READWRITE, ON_CHANGE, onSchedulerTestChange);
ArduinoCloud.addProperty(light, READWRITE, ON_CHANGE, onLightChange);
ArduinoCloud.addProperty(time_read, READ, ON_CHANGE, NULL, 10);
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
Come Widget uso lo Scheduler, il Time Picker, il Value e tre LED.
le varie configurazioni penso di averle fatte giuste sia come tipo di variabili che come Permission.
Accetto suggerimenti.