GPIO Interface

From Embedded Systems Learning Academy
Jump to: navigation, search

This article shows how to use one of the pins on the SJ-One board as either an INPUT or OUTPUT pin.

Steps

The latest version of sample projects or development folder includes a GPIO C++ class. To use a pin for GPIO, see the source code example below :

/// Include the GPIO file
#include "gpio.hpp"

int main(void)
{
   /**
    * Locate a pin on your board that you'd 
    * like to use either as INPUT or OUTPUT
    * Let's use P1.19 (as labeled on the Board)
    *
    * You can use any other pins as defined by
    * LPC1758_GPIO enumeration at gpio.hpp file.
    */
    GPIO myPin(P1_19);   // Control P1.19
    myPin.setAsOutput(); // Use the pin as output pin

    // Let's blink an LED on P1.19 :
    while(1) {
        myPin.setHigh();     // Pin will now be at 3.3v
        delay_ms(100);

        myPin.setLow();      // Pin will now be at 0.0v
        delay_ms(100);
    }

    return 0;
}