Hi,
I would like to reset at each start of the program the variables contained in the "Reset()" function, but it doesn't work.
I can't figure out why.
The sketch is as follows:
#include "arduino_secrets.h"
/************************** v3.0 *******************************************************
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/544cfaeb-9ad1-42b1-8ba0-9e866c825cea
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int erogazioni;
bool led14;
bool led20;
bool led8;
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 <Stepper.h>
#define STEPS 400
int ora = 17;
bool flag = true;
bool zero = true;
// steppr motor: IN1 D2(2), IN2 D3(3), IN3 D4(4), IN4 D5(5)
Stepper stepper(STEPS, 2, 3, 4, 5);
int start = 6; // D6 pin 6
int val = 900;
int calval = 50;
void setup() {
Serial.begin(9600);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
led8 = false;
led14 = false;
led20 = false;
pinMode(6, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
stepper.setSpeed(100);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
}
void eroga(){
stepper.step(val);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
erogazioni++;
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
}
void Azzera(){
erogazioni = 0;
led8 = false;
led14 = false;
led20 = false;
zero = false;
}
void loop() {
ArduinoCloud.update();
unsigned long now = ArduinoCloud.getLocalTime(); // scarica ora e minuti correnti
time_t now_time = (time_t)now;
struct tm* timeinfo = localtime(&now_time);
Serial.println("now:" + String(timeinfo->tm_hour) + ":" + String(timeinfo->tm_min)+ ":" + String(timeinfo->tm_sec));
if (((timeinfo->tm_hour) == ora) && ((timeinfo->tm_min) == 53) && ((timeinfo->tm_sec) == 10)) {
if(flag == true){
eroga();;
led8 = true;
Serial.print(" ore 8 --> ");
Serial.println(erogazioni);
flag = false;
}
}
if (((timeinfo->tm_hour) == ora) && ((timeinfo->tm_min) == 54) && ((timeinfo->tm_sec) == 10)) {
if(flag == false){
eroga();
led14 = true;
Serial.print(" ore 14 --> ");
Serial.println(erogazioni);
flag = true;
}
}
if (((timeinfo->tm_hour) == ora) && ((timeinfo->tm_min) == 55) && ((timeinfo->tm_sec) == 10)) {
if(flag == true){
eroga();
led20 = true;
Serial.print(" ore 20 --> ");
Serial.println(erogazioni);
flag = false;
}
}
if (((timeinfo->tm_hour) == ora) && ((timeinfo->tm_min) == 56) && ((timeinfo->tm_sec) == 10)) {
led8 = false;
led14 = false;
led20 = false;
if(flag == false){
Serial.println(" ore 23 --> Azzeramento");
flag = true; // riabilita gli orari per il giorno dopo
}
}
if (zero == true){
Azzera(); // Initially resets variables to zero
}
}
/*
Since Erogazioni is READ_WRITE variable, onErogazioniChange() is
executed every time a new value is received from IoT Cloud.
*/
void onErogazioniChange() {
// Add your code here to act upon Erogazioni change
}
/*
Since Led8 is READ_WRITE variable, onLed8Change() is
executed every time a new value is received from IoT Cloud.
*/
void onLed8Change() {
// Add your code here to act upon Led8 change
}
/*
Since Led14 is READ_WRITE variable, onLed14Change() is
executed every time a new value is received from IoT Cloud.
*/
void onLed14Change() {
// Add your code here to act upon Led14 change
}
/*
Since Led20 is READ_WRITE variable, onLed20Change() is
executed every time a new value is received from IoT Cloud.
*/
void onLed20Change() {
// Add your code here to act upon Led20 change
}
EzioGi