why is this code not working in Arduino iot cloud. I want to broadcast it over the air.
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/971ca962-22e2-4336-940a-0668a8cc1d6e
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
- No variables have been created, add cloud variables on the Thing Setup page
to see them declared here
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>
#include <FastLED.h>
#define NUM_LEDS 12
#define DATA_PIN 8
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define BRIGHTNESS 50
#define VOLTS 5
#define MAX_AMPS 500
CRGB leds[NUM_LEDS];
int Relay = 4;
RTCZero rtc;
// Removed the const keyword so the variables can be updated
byte seconds = 00;
byte minutes = 29;
byte hours = 5;
byte day = 4;
byte month = 12;
byte year = 23;
int OnTime = 330;
int OnTime2 = 1020;
int OffTime1 = 480;
int OffTime2 = 1380;
//5:30=330 min
//8=480 min
//17=1020 min
//23=1380 min
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);
rtc.begin(); // initialize RTC
pinMode(Relay, OUTPUT);
digitalWrite(Relay, LOW);
rtc.setHours(hours);
rtc.setMinutes(minutes);
rtc.setSeconds(seconds);
rtc.setDay(day);
rtc.setMonth(month);
rtc.setYear(year);
FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(VOLTS, MAX_AMPS);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
// 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();
// Your code here
print2digits(rtc.getDay());
Serial.print("/");
print2digits(rtc.getMonth());
Serial.print("/");
print2digits(rtc.getYear());
Serial.print(" ");
print2digits(hours = rtc.getHours()); // We update the hours variable like this here
Serial.print(":");
print2digits(minutes = rtc.getMinutes()); // We update the minutes variable like this here
Serial.print(":");
print2digits(rtc.getSeconds());
Serial.println();
updateRelay(); // we update the relay here
delay(1000);
}
void print2digits(int number) {
if (number < 10) {
Serial.print("0"); // print a 0 before if the number is < than 10
}
Serial.print(number);
}
// moved the relay code to it's own function
void updateRelay() {
int mOnTime = hours * 60 + minutes;
if ((mOnTime >= OnTime && mOnTime <= OffTime1) || (mOnTime >= OnTime2 && mOnTime <= OffTime2)) {
digitalWrite(Relay, HIGH);
Serial.println("LIGHT ON");
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = CRGB::White;
FastLED.show();
delay(50);
}
} else {
digitalWrite(Relay, LOW);
Serial.println("LIGHT OFF");
}
}