Tutorial: Spark Variable and Function on One Web Page

Hi @Dup

If you are doing an analogRead of a pin that is not driven by anything, you will just get random values. Tinker is just am example–you can do your own thing very easily.

If you want to use a Spark.function to set a parameter, that is, something you want to change to “tune” you code to behave better on the fly, that is a perfect use. You would just do:

int myParam = 0;  // or other initial value

void setup()
{
  Spark.function("setparam", setParam);
  Spark.variable("getparam", &myParam, INT);
  // whatever other setup you need
}

void loop() {
//you code that uses myParam
}

int setParam(String paramValue) {
    myParam = paramValue.toInt();
    return 0;
}

Now from the web page you can read and set the parameter value and in your program, you just use myParam however you want.

1 Like