When i have requested from the core

Hi Guys,

I hope someone can help me.

Im trying to make a button, which can count with the spark core.

I did make the button so it works on the core, and i can get the information from the core.

Is there any way, i can reset the count i have on the core, when i get the value with CURL?

Any ideas?

My code: :smiley:

int status = 0;
int count ;

void setup()
{
   Spark.variable("status", &status, INT);
   pinMode(D0, INPUT);
}
 
void loop()
{
  if(digitalRead(D0) == HIGH){
      count++;
      delay(500);
      status = count;
  }  
}

Thank you!

1 Like

You could provide a Spark.function() that does the resetting.
And since such a function does have an int return value, you could even forget the Spark.varilble()

If you call the fn with an empty parameter you just use the return value and when providing a param (e.g. β€œreset”) you do just this.

int count = 0;

void setup()
{
  Spark.function("doIt", doIt);
  pinMode(D0, INPUT_PULLUP);  // if your button pulls to ground 
}

void loop()
{
  if(digitalRead(D0) == HIGH){
    count++;
    delay(500);
    //status = count;
  }  
}

int doIt(String param)
{
  if (param == "reset")
    count = 0;

  return count;
}
4 Likes

Wow, Thank you Scruffr,
I will test this as soon as possible! :smile: