wiki:Example2.1

Examples

Example2.1

Wait until user DIP switches (Pin 1 and 2) changed, then drive 20 cm forward.

example2_1/main.c:

#include <all.h>

int
main(void) 
{
        /* initialize devices */
        init_all();

        /* endless loop */
        while(1) {
                /* get current switch state */
                uint8_t switch_state = get_user_switches();
                /* wait (and blink) until user switches changed */
                while(get_user_switches() == switch_state) {
                        /* blink with front LED ... */
                        led_on(FRONT);
                        delay_ms(500);
                        led_off(FRONT);
                        delay_ms(500);
                }

                /* wait for 2 seconds */
                delay_ms(2000);

                /* move 20 cm forward */
                pwmdrive_go_cm(FORWARD, 20, NULL);
        }

        return 0;
}
Last modified 7 years ago Last modified on Nov 23, 2011, 11:25:35 AM