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

lcd.begin(16,2);


             After this setup procedure you can now call the functions print() and setCursor()
        commands  to  print  any  given  text  to  any  particular  place  on  the  LCD  display.  The
        positions on the screen are indexed starting with (0,0) in the top left of the screen. The first

        argument  setCursor()  specifies  the  column  number,  and  the  second  specifies  the  row
        number. By default, the starting location is always (0,0). So if you call the first command
        print()  without  first  changing  the  cursor  position,  it  will  print  starting  in  the  top-left

        corner.

        NOTE The library does not check to see if the text you are printing fits in the display, so
           make sure your text is within the 16-character limit.

             This  experiment  is  a  great  example  of  how  to  display  information  using  an  LCD
        display.  The  display  can  also  show  information  from  sensors,  such  as  temperature  and

        humidity, as well as date and time stamps. You should now be able to experiment with
        displaying other information.





        Analog Outputs



        Now that we have looked at digital output controls, it is time to understand a bit about the
        analog pins on the Photon board. Although controlling digital components is good, what if
        we wanted to control them with a bit more precision, such as the brightness of an LED or
        the speed of a motor? Well, you can’t normally do this using a digital system, but there is a
        way using a simple digital-to-analog convertor (DAC) chip and using something called

        pulse width modulation (PWM).




        Pulse Width Modulation

        First  let’s  take  a  look  at  using  PWM,  which  is  commonly  found  on  most  single-board

        computing  devices  such  as  the  Photon.  This  method  allows  you  to  get  pretty  close  to
        generating  analog  values  by  emulating  what  an  analog  signal  should  be  like.  On  the
        Photon board five analog pins are available, which all generate PWM signals—these pins

        are labeled A0–A5.

             Let’s go back to our first experiment in this chapter where we flashed an LED on and
        off. We will use that same circuit, but instead of connecting the LED to digital pin D0, we
        can connect it to pin A0 as shown in the breadboard layout diagram in Figure 4.8.
   81   82   83   84   85   86   87   88   89   90   91