Basic IO

GPIO 

#include "gpio.hpp"
#include "utilities.h"

int main(void)
{
	/* Use P1.20 as General Purpose Input/Output (GPIO) */
    GPIO pin20(P1_20);
    /* Use this pin as OUTPUT */
    pin20.setAsOutput(); 
	/* Turn on voltage to 3.3v */
    pin20.setHigh(); 
    /* Turn off voltage to 0v  */
    pin20.setLow();  
}

ADC Input

#include "adc0.h"
 
void adc_read(void)
{
    /*********************************************************
     * ADC is already initialized before main() is called.
     * There are 3 ADC pins labeled on the SJ-One board.
     * You can use one or more channels as illustrated below.
     */

    LPC_PINCON->PINSEL1 |= (1 << 20); // ADC-3 is on P0.26, select this as ADC0.3
    LPC_PINCON->PINSEL3 |= (3 << 28); // ADC-4 is on P1.30, select this as ADC0.4
    LPC_PINCON->PINSEL3 |= (3 << 30); // ADC-5 is on P1.31, select this as ADC0.5

    int adc3 = adc0_get_reading(3); // Read the value of ADC-3
    int adc4 = adc0_get_reading(4); // Read the value of ADC-4
    int adc5 = adc0_get_reading(5); // Read the value of ADC-5
}

PWM and Servo Control

#include "lpc_pwm.hpp"

/**
 * You can control up to 6 servos with hardware signals (and more with sw)
 * Each signal is mapped to from P2.0 to P2.5
 */
void motor_control()
{
    /* Use 1Khz PWM.  Each PWM shares the 1st frequency you set */
    PWM motor1(PWM::pwm1, 1000);
    PWM motor2(PWM::pwm2, 0);

    /* Set to 50% motor speed */
    motor1.set(50);
    motor2.set(50);
}
void servo_control()
{
    /* Use 50Hz PWM for servos.  Each PWM will be 50Hz */
    PWM servo1(PWM::pwm1, 50);
    PWM servo2(PWM::pwm2, 0);

    servo1.set(5.0);  ///< Set to left position
    servo2.set(10.0); ///< Set to right position
}
Back to top