I've been trying to give static string to the Value Widget in the sketch but the value does not reflect in the Value Widget. I have already made the variable and attached it to the widget.
e.g,
The variable which I created in things is "abc" with string datatype.
in the setup() function I am trying to assign it in this way:
abc = "Hello";
But its not reflecting.
The basic logic which I want to apply is like when I give a certain degree to my servo variable, I want to print some string against the value;
e.g: if my servo I turn servo using another widgets and it retrun 90 degrees, so I want to display "Hot" against 90 in Value Widget.
if ( servo1 == 90)
{
abc = "Hot";
}
May be I am missing out something in my logic.
even by returning a static string to the Value will get me going from there. Thanks in advance for the help.
We need to see your complete code. If that is too long, please post a short sketch which illustrates the problem.
For example, in C/C++ there is string (array of char) and there is String, and they are different. This confusion may be the reason for your problem. With string (array of char) you cannot use abc = "123". You must use strcpy(), and you must ensure the char array will always be large enough. With String, it is easier, but if your "widget" is expecting a string (array of char) you may need to use abc.c_str().
Currently the code is very simple. I removed the default comments from the code to avoid verbosity.
String temp;
int servo;
#include "thingProperties.h"
#include "Servo.h"
Servo servo1;
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
delay(1500);
servo1.attach(D1);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
servo1.write(servo);
// Your code here
if(servo == 105)
{
temp = "Hot"; //Here I want to change the variable data of temp on servo degree change.
}
}
please, please never ever again post pictures of text... Not only they are not readable nor usable directly for copy&paste but they use up lots of storage and internet bandwidth which contributes to polluting the planet.
➜ do your part and do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).
Well about the variable on the top, I was removing the comments and left these variables which were present in the comments. At first I thought it was part of the code but later I realized it was part of comments which I should have removed.