I've seen plenty of solutions to this problem online, but I can't find a way to do it that doesn't involve using a physical button...my goal is to switch on and off via dashboard widget in Arduino IoT Cloud...not a physical switch...(note: there's no input pin)
I have been able to code my MKR WiFi 1010 and LED to turn and off via the dashboard widget (switch) but only as a blink function...meaning that when the "delay" time is over, the LED turns off
I can't figure out how to make it STAY on, and only turn off when I hit the on/off switch on my dashboard widget...
my goal is to switch a lamp on/off with my phone or computer. I started with an LED to write the code first.
THANKS IN ADVANCE!
I go to my website, select on or off, click submit. Many miles away a LED turns on/off and stays that way till changed from the web site.
After looking at the posted code, I can see that the code is missing. Missing code does not run very well nor can it be troubleshot easily. Most of the time people, on this site, like the code, well formatted, to be in code tags.
So if your code is posted you could write about what its supposed to do, what it does instead, and the part of the program you are currently working on that is doing the problem.
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/74a37c64-d1a9-4e93-b650-038c342e6224
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudLight lEDSwitch;
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"
const int LEDpin = 6;
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 (LEDpin, 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();
// Your code here
}
void onLEDSwitchChange()
{
// Do something
digitalWrite (LEDpin, HIGH);
}
The following variables are automatically generated and updated when changes are made to the Thing
CloudLight lEDSwitch;
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"
const int LEDpin = 6;
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 (LEDpin, 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();
digitalWrite (LEDpin, LOW); // Your code here
}
void onLEDSwitchChange()
{
// Do something
digitalWrite (LEDpin, HIGH);
delay (6000);
}