I’m wondering if anyone knows how to translate data from 4 x Text Widgets into an array which subsequently selects a matched value from the array.
At the moment I’ve able to do it with the values declared in the code but failed in the array seeing the values entered in the Text Widget… my working code looks something like this…
int accessIDcount = 4;
int accessIDs[] = {1234, 2345, 3456, 4567};
.
.
.
.
for (int k = 0; k < accessIDcount; k++){
Serial.println(accessIDs[k]);
if (a == accessIDs[k]){
knownAccessID = true;
//Serial.println(knownAccessID);
}
}
Yes @Costas I guess because the value from the text input comes in as a string. I’ve tried a number of combinations to get the array working such as converting string to int using .toInt()
I think there’s potentially two traps that you’re falling in to here…
As @Costas said, you’re taking string values and treating them as integers in your comparison, so they’ll never evaluate as a match.
You might be getting caught out with the scope of your variables. String accessID1 = param.asStr declares accessID1 as being local to that BLYNK_WRITE function, so when you try to reference it outside of the function you’ll either get a compile error saying that it wasn’t declared in this scope, or if you declare it as a global variable then you’re effectively re-declaring the variable within your BLYNK_WRITE function.
I’ve tried declaring String accessIDs; globally but for some reason the the Blynk Write data from the text input widget isn’t recognised in the array initialisation.
The code relating to this issue is gone. I’ve reverted back to what is working and that is declaring the values as mentioned in my first post… I just thought if anyone knew how to grab the data from the text input string and have recognised in the array initialisation it would be very helpful to enter that value via the app.