Hi everyone,
I'm using a R4 WIFI board with Arduino Cloud, my goal is pretty simple:
I would like to control two servomotors at the same time, to do this I created a dashboard containing 1 switch, 1 input angle and 1 scheduler; for each of the servomotors.
The servomotors must position themselves at the indicated angle when the switch is ON and the scheduler is at True (the servomotors must be independent from each other), otherwise they position themselves in a default angle.
My problem is one scheduler is working and the other just isn't, the variable configuration is the same between the schedules:
Below is my code:
/*
Sketch generated by the Arduino IoT Cloud Thing "Cloud Blink"
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int angle1;
int angle2;
CloudSchedule scheduler1;
CloudSchedule scheduler2;
bool button1;
bool button2;
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 <Servo.h>
Servo myServo1; // create a servo object
Servo myServo2; // create a servo object
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);
/*
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(4);
ArduinoCloud.printDebugInfo();
pinMode(LED_BUILTIN, OUTPUT);
myServo1.attach(11); // attaches the servo 1 on pin 11 to the servo object
myServo2.attach(9); // attaches the servo 2 on pin 9 to the servo object
}
void loop() {
ArduinoCloud.update();
// SERVO 1
if (button1 && scheduler1.isActive()) {
Serial.println("Servo-1 is active:");
Serial.print("Button-1: ");
Serial.println(button1);
Serial.print("Scheduler-1: ");
Serial.println(scheduler1.isActive());
myServo1.write(angle1);
delay(10);
}
else{
Serial.println("Servo-1 is NOT active:");
Serial.print("Button-1: ");
Serial.println(button1);
Serial.print("Scheduler-1: ");
Serial.println(scheduler1.isActive());
myServo1.write(0);
delay(10);
}
// SERVO 2
if (button2 && scheduler2.isActive()) {
Serial.println("Servo-2 is active:");
Serial.print("Button-2: ");
Serial.println(button2);
Serial.print("Scheduler-2: ");
Serial.println(scheduler2.isActive());
myServo2.write(angle2);
delay(10);
}
else{
Serial.println("Servo-2 is NOT active:");
Serial.print("Button-2: ");
Serial.println(button2);
Serial.print("Scheduler-2: ");
Serial.println(scheduler2.isActive());
myServo2.write(0);
delay(10);
}
}
/*
Since is READ_WRITE variable, onAngle1Change() is
executed every time a new value is received from IoT Cloud.
*/
void onAngle1Change() {
// Add your code here to act upon Angle1 change
}
void onAngle2Change() {
// Add your code here to act upon Angle2 change
}
void onScheduler1Change() {
// Add your code here to act upon Scheduler1 change
}
void onScheduler2Change() {
// Add your code here to act upon Scheduler2 change
}
void onButton1Change() {
// Add your code here to act upon Button1 change
}
void onButton2Change() {
// Add your code here to act upon Button2 change
}
With the following configuration both the servomotors should position themselves at 90°
But only the servo-2 is working, for some reason the schedule-1 is returning False even tho it should be True, as you can see even in the Serial Monitor:

I hope someone can help because I really don't know what i'm doing worng.
Thanks in advance!

