Skip to content
Serge Vakulenko edited this page May 15, 2015 · 4 revisions

This is a two-color LED module.

Two-color LED example for RetroBSD on Olimex Duinomite board. LED module is connected to pins D0 and D1 pins of Duinomite board (signals RE0 and RE1 of pic32 chip).

Shell example using portio

Blink every LED component in series.

# Set signals RE0 and RE1 as output.
portio -o e0 e1
portio -c e0 e1

while :
do
    portio -c e0 -s e1
    portio -c e1 -s e0
done

Shell example using /dev/porte device

Blink every LED component in series for one second.

# Set signals RE0 and RE1 as output.
echo --------------oo > /dev/confe
echo --------------00 > /dev/porte

while :
do
    echo --------------10 > /dev/porte
    sleep 1
    echo --------------01 > /dev/porte
    sleep 1
done

C example

Blink every LED component in series for 100 milliseconds.

#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/gpio.h>

#define MASK_D0     (1 << 0)    /* signal RE0 */
#define MASK_D1     (1 << 1)    /* signal RE1 */

int main()
{
    int fd;
    char *devname = "/dev/porta";

    /* Open GPIO driver. */
    fd = open(devname, 1);
    if (fd < 0) {
        perror(devname);
        return -1;
    }

    /* Configure pins as output. */
    ioctl(fd, GPIO_PORTE | GPIO_CONFOUT, MASK_D0 | MASK_D1);
    ioctl(fd, GPIO_PORTE | GPIO_CLEAR, MASK_D0 | MASK_D1);

    for (;;) {
        /* Clear D0, set D1. */
        ioctl(fd, GPIO_PORTE | GPIO_CLEAR, MASK_D0);
        ioctl(fd, GPIO_PORTE | GPIO_SET, MASK_D1);
        usleep(250000);

        /* Clear D1, set D0. */
        ioctl(fd, GPIO_PORTE | GPIO_CLEAR, MASK_D1);
        ioctl(fd, GPIO_PORTE | GPIO_SET, MASK_D0);
        usleep(250000);
    }
    return 0;
}

To compile and run this program, use:

# cc led2.c -o led2
# ./led2