Hello, everyone!
I'm starting a project where I need to turn on/off a water pump through the IOT Calendar and I also would like to turn it on with a switch.
But I would like to turn the pump off with the switch (using it as a emergency button).
So basically I want to be able to turn the pump "manually" with the switch, ou using the calendar and be able to turn the pump off with the same switch.
Here is my code so far:
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/758ca0da-74e6-4361-9014-33d2deb21fff
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudLight led;
CloudSwitch switch1;
CloudSchedule calendar;
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"
#define pump 10
#define ferti 11
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);
pinMode(10, 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();
}
void loop() {
ArduinoCloud.update();
if (calendar.isActive()){
digitalWrite(10, HIGH);
Serial.println("Calendar activated");
delay(500);
} else
{
digitalWrite(10, LOW);
Serial.println("Calendar deactivated");
delay(500);
}
/*if (led == 1){
digitalWrite(10, HIGH);
Serial.println("On by button");
delay(500);
} else{
digitalWrite(10, LOW);
Serial.println("Off by button");
delay(500);
}*/
}
void onLedChange() {
if (led == 1){
digitalWrite(10, HIGH);
Serial.println("On by button");
delay(500);
} else{
digitalWrite(10, LOW);
Serial.println("Off by button");
delay(500);
}
}
void onCalendarChange() {
// Add your code here to act upon Calendar change
}
void onSwitch1Change() {
}
Thanks in advance!
Fernando