\section{Lighting the LED from Julia}
\subsection{Lighting the LED}
\label{sec:light-julia}
In this section, we discuss how to carry out the experiments of the
previous section from Julia.  We will list the same four experiments,
in the same order.  The shield has to be attached to the \arduino\ board
before doing these experiments and the \arduino\ needs to be connected to the computer 
with a USB cable, as shown in \figref{arduino}.
The reader should go through the instructions given in \secref{sec:julia-start} before getting started.

\begin{enumerate}
  \item In the first experiment, we will light up the blue LED on the
        shield.  The code for this is given in \juliaref{julia:led-blue}.
        It begins with importing the SerialPorts \cite{julia-serial-ports} package 
        and the module ArduinoTools, as given in \secref{sec:julia-toolbox}. Following lines 
        import SerialPorts and ArduinoTools:
        \lstinputlisting[firstline=1,lastline=2]{\LocLEDjuliacode/led-blue.jl}

        Next, the following line of code is used to detect the port on which \arduino\
        is connected. 
        \lstinputlisting[firstline=4,lastline=4]{\LocLEDjuliacode/led-blue.jl}
      Apart from detecting the port, it also opens a serial port with given BAUD RATE. 
      In this experiment, we have to put a high voltage (5V) on pin 9 to
        turn the blue light on.  This is achieved by the following command:
        \lstinputlisting[firstline=6,lastline=6]{\LocLEDjuliacode/led-blue.jl}
        Before that, we need to define pin 9 as the
        output pin.  This is achieved by the following command: 
        \lstinputlisting[firstline=5,lastline=5]{\LocLEDjuliacode/led-blue.jl}
        The last line in the code closes the serial port. 
        In this Julia source file, one can observe that the blue light will be on continuously.   
\item \juliaref{julia:led-blue-delay} does the same thing as what
        \ardref{ard:led-blue-delay} does.  It does two more things than what
        \juliaref{julia:led-blue} does: It makes the blue LED light up for two
        seconds.  This is achieved by the command
      \lstinputlisting[firstline=7,lastline=7]{\LocLEDjuliacode/led-blue-delay.jl}
      The second thing this code does is to turn the blue LED off.  This
        is achieved by the command
        \lstinputlisting[firstline=8,lastline=8]{\LocLEDjuliacode/led-blue-delay.jl}
        It is easy to see that this code puts a 0 on pin 9.
  \item \juliaref{julia:led-blue-red} does the same thing as what
        \ardref{ard:led-blue-red} does.  It turns blue and red LEDs on for
        five seconds.  After that, it turns off blue first.  After 3
        seconds, it turns off red also.  So, when the program ends, no LED is
        lit up.
        
  \item \juliaref{julia:led-green-blink} does exactly what its counterpart
        in the Arduino IDE does.  It makes the green LED blink five times.
\end{enumerate}


\subsection{Julia Code}
\lstset{style=mystyle}
\label{sec:led-julia-code}
\addtocontents{juliad}{\protect\addvspace{\codclr}}

\begin{juliacode}
  \jcaption{Turning on the blue LED}
  {Turning on the blue LED.  Available at
    \LocLEDjuliabrief{led-blue.jl}.}
  \label{julia:led-blue}
  \lstinputlisting{\LocLEDjuliacode/led-blue.jl}
\end{juliacode}

\begin{juliacode}
  \jcaption{Turning on the blue LED and turning it off after two
    seconds}{Turning on the blue LED and turning it off after two
    seconds.  Available  
    at \LocLEDjuliabrief{led-blue-delay.jl}.}
  \label{julia:led-blue-delay}
  \lstinputlisting{\LocLEDjuliacode/led-blue-delay.jl}
\end{juliacode}

\begin{juliacode}
  \jcaption{Turning on blue and red LEDs for 5 seconds and then turning
    them off one by one}{Turning on blue and red LEDs for 5 seconds and
    then turning them off one by one.  Available at
    \LocLEDjuliabrief{led-blue-red.jl}.}
  \label{julia:led-blue-red}
  \lstinputlisting{\LocLEDjuliacode/led-blue-red.jl}
\end{juliacode}

\begin{juliacode}
  \jcaption{Blinking the green LED}{Blinking the green LED.  Available
    at \LocLEDjuliabrief{led-green-blink.jl}.}
  \label{julia:led-green-blink}
  \lstinputlisting{\LocLEDjuliacode/led-green-blink.jl}
\end{juliacode}



