Пример #1
0
static void *btn_handler_function (void *arg)
{
    uint32_t last = xtimer_now();
    int i;
    flag_state = 0;
    while (1)
    {
    	i = gpio_read(BTN_B1_PIN);
   	if (i != 0) {
		if ( flag_state == 0  )
			{
				LED6_ON;
				flag_state = 1;
				xtimer_usleep_until(&last, 1000000);
			}
		else {  
			LED6_OFF;
			flag_state = 0;
			xtimer_usleep_until(&last, 1000000);
			}		
		}
	xtimer_usleep_until(&last, 100000);
    }
    return NULL;
}
Пример #2
0
int main(void)
{
    uint32_t last = xtimer_now();
    int sample = 0;

    puts("\nRIOT ADC peripheral driver test\n");
    puts("This test will sample all available ADC lines once every 100ms with\n"
         "a 10-bit resolution and print the sampled results to STDIO\n\n");

    /* initialize all available ADC lines */
    for (int i = 0; i < ADC_NUMOF; i++) {
        if (adc_init(ADC_LINE(i)) < 0) {
            printf("Initialization of ADC_LINE(%i) failed\n", i);
            return 1;
        } else {
            printf("Successfully initialized ADC_LINE(%i)\n", i);
        }
    }

    while (1) {
        for (int i = 0; i < ADC_NUMOF; i++) {
            sample = adc_sample(ADC_LINE(i), RES);
            if (sample < 0) {
                printf("ADC_LINE(%i): 10-bit resolution not applicable\n", i);
            } else {
                printf("ADC_LINE(%i): %i\n", i, sample);
            }
        }
        xtimer_usleep_until(&last, DELAY);
    }

    return 0;
}
Пример #3
0
int main(void)
{
    phydat_t res;
    uint32_t last = xtimer_now();

    puts("SAUL test application");

    while (1) {
        saul_reg_t *dev = saul_reg;

        if (dev == NULL) {
            puts("No SAUL devices present");
            return 1;
        }

        while (dev) {
            int dim = saul_reg_read(dev, &res);
            phydat_dump(&res, dim);
            dev = dev->next;
        }

        xtimer_usleep_until(&last, INTERVAL);
    }

    return 0;
}
Пример #4
0
static void *colllision_detection(void *arg)
{
    uint32_t lw = xtimer_now();

    while (1) {
        /* trigger sensor reading */
        srf02_trigger(&dist_front, SRF02_MODE_REAL_CM);
        srf02_trigger(&dist_back, SRF02_MODE_REAL_CM);
        /* wait for results */
        xtimer_usleep(SRF02_RANGE_DELAY);
        /* read distance data */
        front_filter[filter_pos] = srf02_read(&dist_front);
        xtimer_usleep(1);   /* hack, otherwise the 2nd srf02_read f***s up */
        back_filter[filter_pos] = srf02_read(&dist_back);
        // printf(" f: %3i,  b: %3i  %i\n", (int)front_filter[filter_pos], (int)back_filter[filter_pos], filter_pos);
        filter_pos = (++filter_pos >= FILTER_SIZE) ? 0 : filter_pos;

        /* analyze data and trigger events base on it */
        uint16_t fd = 0;
        uint16_t bd = 0;
        for (int i = 0; i < FILTER_SIZE; i++) {
            fd += front_filter[i];
            bd += back_filter[i];
        }
        if ((fd < (FILTER_SIZE * CONF_DIST_THOLD)) && (front_blocked == 0)) {
            front_blocked = 1;
            event(EVT_FRONT_BLOCKED);
        }
        else if ((fd >= (FILTER_SIZE * CONF_DIST_THOLD)) && (front_blocked == 1)) {
            front_blocked = 0;
            event(EVT_FRONT_FREE);
        }
        if ((bd < (FILTER_SIZE * CONF_DIST_THOLD)) && (back_blocked == 0)) {
            back_blocked = 1;
            event(EVT_BACK_BLOCKED);
        }
        else if ((bd >= (FILTER_SIZE * CONF_DIST_THOLD)) && (back_blocked == 1)) {
            back_blocked = 0;
            event(EVT_BACK_FREE);
        }

        xtimer_usleep_until(&lw, CONF_DIST_SENSE_DELAY);
    }

    return NULL;
}
Пример #5
0
int main(void)
{
    int state = 0;
    int step = STEP;
    uint32_t last_wakeup = xtimer_now();

    puts("\nRIOT PWM test");
    puts("Connect an LED or scope to PWM pins to see something\n");

    printf("Available PWM devices: %i\n", PWM_NUMOF);
    for (int i = 0; i < PWM_NUMOF; i++) {
        uint32_t real_f = pwm_init(PWM_DEV(i), MODE, FREQU, STEPS);
        if (real_f == 0) {
            printf("Error initializing PWM_%i\n", i);
            return 1;
        }
        else {
            printf("Initialized PWM_%i @ %" PRIu32 "Hz\n", i, real_f);
        }
    }

    puts("\nLetting the PWM pins oscillate now...");
    while (1) {
        for (int i = 0; i < PWM_NUMOF; i++) {
            for (uint8_t chan = 0; chan < pwm_channels(PWM_DEV(i)); chan++) {
                pwm_set(PWM_DEV(i), chan, state);
            }
        }

        state += step;
        if (state <= 0 || state >= STEPS) {
            step = -step;
        }

        xtimer_usleep_until(&last_wakeup, INTERVAL);
    }

    return 0;
}