Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

2. Intruder Alarm > Software

Software

The source code for the app can also be downloaded from the book’s website.

Much of the framework for the app is similar to that of the HelloIOIO example of Chapter 1, so we will just look at the parts of the code concerned with interfacing to the PIR sensor.

protected void setup() throws ConnectionLostException {
        pir_ = ioio_.openDigitalInput(48, Mode.FLOATING);
        led_ = ioio_.openDigitalOutput(0);
}

The setup method opens a digital input on pin 48 for the PIR sensor and a digital output for the built-in LED on the IOIO. This LED will flicker on whenever movement has occurred.

When opening a digital Input using openDigitalInput, you supply two arguments. The first argument is the pin to open, and the second specifies the mode. This mode can be one of Mode.FLOATING, Mode.PULL_UP or Mode.PULL_DOWN. We have used FLOATING, because the built-in resistors that can be assigned with PULL_UP and PULL_DOWN are too weak for the PIR sensor and we need to use an external pull-up resistor:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint