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

if (n == 1) {
                   digitalWrite(Ledyellow, HIGH);

        }



        else



        This  is  used  in  conjunction  with  the  if  statement.  The  block  of  code  within  the  else
        statement will execute when the  if  statement  returns  a  false  condition  or  when  the  if
        condition is not met.




        Syntax


                   if (condition) {
                   //execute if condition is true
                   }
                   else {

                   //execute if condition is false
                   }



        Example


        int switchstate = digitalRead(D0)

                   if (switchstate == HIGH) {
                              digitalWrite(ledpin, HIGH)
                   }
                   else {

                              digitalWrite(ledpin, LOW)
                   }

        This example is designed to detect if a switch has been pressed. If the switch has been

        pressed and equals HIGH, then the LED turns on. If the switch is equal to LOW, then the
        LED will stay off.




        int


        An integer is a data type that creates a bit of memory to store a single value.




        Example

                   int led = D0;


        This stores the pin number into a memory slot called led. When you want to reference the
   193   194   195   196   197   198   199   200   201   202   203