Page 170 - Programming the Photon Getting Started With the Internet of Things
P. 170

Description                                          Appendix


          Photon board                                        M1


          Grove Particle shield                               M4


          Grove vibration motor                               M4


          Grove buzzer                                        M4




        Table 8.2 Components and Hardware

             The software for this experiment is simple. We create a function that IFTTT passes
        through a value. We then check the value to see if it matches and then indicate what sound
        we want (such as a buzzer) and turn the motor on. The software for this experiment is as
        follows:


        #define MOTORPIN A4

        #define BUZZPIN D1




        void setup() {
            pinMode(MOTORPIN, OUTPUT);

            pinMode(BUZZPIN, OUTPUT);
            Spark.function("Twitter", twitter);
        }



        void loop() {


        }



        int twitter(String command)
        {
            if (command == "buzz")

            {
                digitalWrite(MOTORPIN, HIGH);
                digitalWrite(BUZZPIN, HIGH);
                delay(1000);
                digitalWrite(MOTORPIN, LOW);

                digitalWrite(BUZZPIN, LOW);
                return 1;
            }

            else return -1;
   165   166   167   168   169   170   171   172   173   174   175