Chapter 4


In order to use a digital input we need to ask the question, is the input high or low? Is it a logic 1 or 0?

If it is a 1 then we execute some code, if it is a 0 then we execute some other code. So we are asking the question, if the input is a certain value then execute the code. Let us look at the C code for this If statement.

IF Statement

The if statement looks like this:

if (condition)




As an example if x is equal to 2 then make y = 6 and z = 4 would be:

if (x==2)





NB.  The expression x==2 means if x is equal to 2.

    The expression x=2 in C code means make x=2.

If there is only one line of code, say y = 6, then a shorthand way of writing this without the brackets {} is

if (x==2) y=6;

If–Else ...

Get PIC Projects and Applications using C now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.