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

Figure 5.3 Breadboard layout diagram for connecting a push button.


             Here  is  our  basic  digital  input  sketch,  which  will  use  the  push  button  as  the  input
        device and light up the on-board LED, which is connected to digital pin 7 as an output:


        int pushbutton = D0;

        int led = D7;


        void setup() {
            pinMode(pushbutton, INPUT);

            pinMode(led, OUTPUT);
        }


        void loop() {

            int buttonstate = digitalRead(pushbutton);
            if (buttonstate == HIGH){
                    digitalWrite(led, HIGH);
   94   95   96   97   98   99   100   101   102   103   104