int main(void){
        /* Initialises the switches and LEDs using the LetMeCreate library */
        switch_init();
        led_init();
        
        /* The first parameter is the event for which a callback function will be triggered. The second is a pointer to the function that will run when the event occurs */
        switch_add_callback(SWITCH_1_PRESSED, led_toggle);
        switch_add_callback(SWITCH_2_PRESSED, end_program);
        
        /* running is true until switch 2 is pressed */
        while(running)
                ;
        /* The LEDs are no longer accessible by the program */
        led_release();
        /* Removes all of the callback functions */
        switch_release();
        
        return 0;
}
示例#2
0
int main(void)
{
    switch_init();
    switch_add_callback(SWITCH_ALL_EVENTS, print_hello);
    printf("Switch callback are now active for 15 seconds.\n");
    printf("Press a switch to print \"hello\" on screen.\n");
    sleep(15);
    switch_release();

    return 0;
}