示例#1
0
/*
 * Simple test of digital inputs and outputs.
 * Input sensor (button) is connected to channel 23.
 * Two LEDs are connected to channels 00 and 01.
 * While button is idle, LED1 is off and LED2 is on.
 * When button is pressed, LED1 is turned on, and LED2 turned off.
 */
void test1(dyio_t *d)
{
    int led, button;

    printf("Test 1: button at channel 23, two LEDs at channels 00 and 01.\n");
    dyio_set_mode(d, 23, MODE_DI);
    dyio_set_mode(d, 0, MODE_DO);
    dyio_set_mode(d, 1, MODE_DO);
    led = 0;
    dyio_set_value(d, 0, 0);
    dyio_set_value(d, 1, 1);
    for (;;) {
        button = !dyio_get_value(d, 23);
        if (button != led) {
            printf(button ? "#" : ".");
            led = button;
            dyio_set_value(d, 0, button);
            dyio_set_value(d, 1, !button);
        }
        fflush(stdout);
        usleep(10000);
    }
}
示例#2
0
/*
 * Simple test of digital inputs and outputs.
 * Input sensor (button) is connected to channel 23.
 * Two LEDs are connected to channels 01 and 02.
 * While button is idle, LED1 is off and LED2 is on.
 * When button is pressed, LED1 is turned on, and LED2 is turned off.
 */
void test1()
{
    int led0, led1, button;
    dyio_set_mode(23, MODE_DI);
    dyio_set_mode(0, MODE_DO);
    dyio_set_mode(1, MODE_DO);
    led0 = 0;
    led1 = 0;
    dyio_print_channels();
    for (;;) {
        button = !dyio_get_value(23);
        if (button) {
            if (! led0) {
                printf("#");
                led0 = 1;
                dyio_set_value(0, led0, 0);
            }
            if (led1) {
                led1 = 0;
                dyio_set_value(1, led1, 0);
            }
        } else {
            if (led0) {
                printf(".");
                led0 = 0;
                dyio_set_value(0, led0, 0);
            }
            if (! led1) {
                led1 = 1;
                dyio_set_value(1, led1, 0);
            }
        }
        fflush(stdout);
        usleep(10000);
    }
}