Beginner Tutorial: IFTTT Publish an Event + Spark Internet Button

@Moors7 @christine

Thanks for the tip about the Timer function. Here is the new version of the .ino which works much better, no random firing of the IFTTT. It now gets one reading every 7 seconds.

    //PUT YOUR GLOBAL VARIABLES HERE
    
    Timer myTimer1(7000, my7sFunction);   // activate function every 7 seconds
                                         // Must hold the light on while D7 flashes
    
        
     // Any general setup stuff goes here   
    void setup(){
        
        pinMode(D0, OUTPUT);
        pinMode(D7, OUTPUT);
        myTimer1.start();
        Particle.subscribe("my-lamp-on", myLampFunction, MY_DEVICES);  
        // for using the "DO" IFTTT button or the IF this then that                                                                      
        // must remove ", MY_DEVICES" for Public anyone to access

    }
    
    
    void loop(){
         
      // your looping stuff here
    
    }
    
    
    void my7sFunction(){
        
        static int myCount = 0;
        myCount++;    // not really used but good to keep count
        
        digitalWrite(D7, 1);   // D7 On, flash D7 every 7 seconds
        delay(20);
        digitalWrite(D7, 0);   // D7 Off
        
        if (analogRead(A0) >= 1000){  
            Spark.publish("bright-light", "1000", 60, PRIVATE);
        } 
    
        if (analogRead(A0) <= 30){
            Spark.publish("no-light", "30", 60, PRIVATE);
        } 
          
    }
    
    
    void myLampFunction(const char *event, const char *data){   
 // for the "DO" or "IF" IFTTT buttons
    
            digitalWrite(D0, 1);   // flash D0 for 2 seconds
            delay(2000);
            
            digitalWrite(D0, 0);   // D7 Off
    
      }
1 Like