Hi,
I would like to create an application where I sequentially have 3 LED Widgets light up.
Basically every minute LED1 should light for 10 seconds, then in the next minute LED2 and finally in the other minute LED3.
As an example I started to use and modify the "Scheduler" sketch.
In the Dashboard I inserted the Scheduler Widget, the Time Picker Widget, the Value Widget and 3 LED Widgets.
This is the Dashboard:
As a Device I use a NANO33 IoT.
For the variables I use the ones that are in the table of the scheduler sketch, as well as the association of the variable to the Widget.
The only difference is that I could not find the value variable to associate with the Widget Value.
In fact I had to assign to the 3 LED Widgets the variable light, it does not let me associate another variable.
So I associated the counter variable to the Widget Value and it works but not the way I want.
The modified sketch is as follows:
#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.
*/
#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;
//Serial.print("counter setup = ");
//Serial.println(counter);
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;
Serial.print("counter toggle = ");
Serial.println(counter);
toggle = false;
}
}
else {
light = false;
digitalWrite(LED_BUILTIN, LOW);
toggle = true;
}
if(ArduinoCloud.connected()) {
time_read = ArduinoCloud.getLocalTime();
}
}
void onSchedulerTestChange() {
}
/*
Since Counter is READ_WRITE variable, onCounterChange() is
executed every time a new value is received from IoT Cloud.
*/
void onCounterChange() {
Serial.print("light change = ");
Serial.print(light);
Serial.print(" counter = ");
Serial.println(counter);
}
/*
Since Light is READ_WRITE variable, onLightChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLightChange() {
}
/*
Since ValoreLed is READ_WRITE variable, onValoreLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onValoreLedChange() {
switch (counter) {
case 2:
digitalWrite(LED1, HIGH);
break;
case 4:
digitalWrite(LED2, HIGH);
break;
case 6:
digitalWrite(LED3, HIGH);
break;
case 8:
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
break;
}
}
This is my first attempt to create something and learn how to use the Arduino Cloud.
I welcome advice
EzioGi