This code works in the Arduino web editor but when I try to run it in the IoT cloud it doesn't work, I get error code. i want to be able to send the ota to the mkr1010wifi:
#include <RTCZero.h>
#include <FastLED.h>
#define NUM_LEDS 12
#define DATA_PIN 8
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define BRIGHTNESS 40
#define VOLTS 5
#define MAX_AMPS 500
CRGB leds[NUM_LEDS];
int Relay = 4;
int Relay2 = 7;
RTCZero rtc;
// Removed the const keyword so the variables can be updated
byte seconds = 00;
byte minutes = 54;
byte hours = 12;
byte day = 28;
byte month = 11;
byte year = 23;
void setup() {
Serial.begin(9600);
rtc.begin(); // initialize RTC
pinMode(Relay, OUTPUT);
digitalWrite(Relay, LOW);
pinMode(Relay2, OUTPUT);
digitalWrite(Relay2, 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();
}
void loop() {
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);
}
void updateRelay() {
if ((hours >= 12 && minutes >= 57) && (hours <= 13 && minutes <= 5) || (hours >= 12 && minutes >= 25) && (hours <= 3 && minutes <= 45)) {
digitalWrite(Relay, HIGH);
digitalWrite(Relay2, 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);
digitalWrite(Relay2, LOW);
Serial.println("LIGHT OFF");
}
}
My code in IoT Cloud:
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled 5"
https://create.arduino.cc/cloud/things/2c17f56f-d5c9-4e7b-a9fd-e552406086cf
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
bool ny28;
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 40
#define VOLTS 5
#define MAX_AMPS 500
CRGB leds[NUM_LEDS];
int Relay = 4;
int Relay2 = 7;
RTCZero rtc;
// Removed the const keyword so the variables can be updated
byte seconds = 00;
byte minutes = 13;
byte hours = 15;
byte day = 28;
byte month = 11;
byte year = 23;
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);
pinMode(Relay2, OUTPUT);
digitalWrite(Relay2, 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()
{
if ((hours >= 15 && minutes >= 15) && (hours <= 15 && minutes <= 25) || (hours >= 15 && minutes >= 35) && (hours <= 15 && minutes <= 45)) {
digitalWrite(Relay, HIGH);
digitalWrite(Relay2, 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);
digitalWrite(Relay2, LOW);
Serial.println("LIGHT OFF");
}
}
/*
Since Ny28 is READ_WRITE variable, onNy28Change() is
executed every time a new value is received from IoT Cloud.
*/
void onNy28Change() {
// Add your code here to act upon Ny28 change
// Add your code here to act upon Ws28 change
if(ny28 == 1){
digitalWrite(Relay2, HIGH);
delay(1000);
} else {
digitalWrite(Relay2, LOW);
delay(1000);
}
}