Post an integer to the spark

I have a photoresistor connected to analog input to turn on the lights (if analog input is greater than X turn on the light). I want to use the spark to change the threshold value, instead of flashing with the new value, to post the new value to the spark, something like :
in the spark code

If analogRead(A1) > threshold than
digitalWrite(D1, HIGH);

and to send the value of threshold like this

curl \
  -d access_token=123412341234 \
  -d threshold=40

Did anyone did anything similar or has an idea on how to implement it ?


Hi @coconut

I think it would help you to look at my tutorial for having a variable and function on one web page:

The code there is for a servo but it is very similar to what you need.


Hey @coconut,

that’s easy! :smiley:

You can use a Spark.function() for this purpose. Pass in a value and the function will update the threshold.

int threshold = 0;

void setup(){
  Spark.function("threshold", set_thres);

int set_thres(String value){
   threshold = value.toInt();
   return threshold;

Thank you.

Might want to load the last value from memory ( at startup and then write it whenever it changes (EEPROM.Write) so your threshold value will survive restarts and power failure

1 Like