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

<br>
        <input type="radio" name="args" value="off">Turn the LED off.

        <br>
        <br>
        <input type="submit" value="Do it!">
        </form>
        </center>


             Edit the code in the HTML document so that “your device id goes here” is your actual
        ID and “your access token” is your access token. You can open up a standard text editor to

        save this code as an .html document so that you can open it in your Web browser. Go
        ahead  and  open  the  .html  document  in  your  browser—you  should  be  presented  with  a
        simple form that allows you to select either on or off. When you click the Do it! button
        you are posting information to the URL https://api.particle.io/v1/devices/your-device-ID-

        goes-here/led?access_token=your-access-token-goes-here. The information you are giving
        is  the  argument  value  ON  or  OFF.  This  parses  through  the  spark.function  that  we
        registered. When you send the information, you will also get some information back from
        the page once sent that gives the status of your deice and lets you know that the post was

        successfully sent to the Photon board. If you want to go back, just click the back button in
        your browser.





        Reading Values over the Internet



        Now that we understand how to send commands to the board to turn things on or off, we
        also need to learn how to read values from sensors such as temperature, humidity, or light.
        We can refer back to Chapter 5 where we used the analog pins on the Photon board to read
        sensor information—these pins are labeled A0–A5. We can only connect components to

        the analog pin, where we know that the voltage can vary between 0 V and 3.3 V; any
        higher  voltages  will  damage  the  Photon  board  as  well  as  the  component  itself.  The
        principle  of  reading  anything  from  the  analog  pins  is  quite  simple;  take  a  look  at  the
        following code:


        int getvalue = 0;
        int analogPin = A0;



        void setup() {
            Spark.variable("analog", &getvalue, INT);

            }


        void loop() {
            getvalue = analogRead(analogPin);
            }
   120   121   122   123   124   125   126   127   128   129   130