This sample blinks the board’s status LED five times, half a second on and half a second off, through the LED class: the same code drives an LED on a GPIO or one channel of an LED controller.
pbl samples samples/drivers/led
every board
#include <stdio.h>
#include <pbl/drivers/led.h>
#include <pbl/kernel/delay.h>
#define BLINKS 5
#define PERIOD_MS 1000
int main(void) {
int ret;
for (int i = 0; i < BLINKS; i++) {
ret = pbl_led_set(STATUS_LED, PBL_LED_BRIGHTNESS_MAX, 0xffffffU);
if (ret != 0) {
fprintf(stderr, "led: on failed (%d)\n", ret);
return ret;
}
printf("led: on\n");
pbl_sleep_ms(PERIOD_MS / 2);
ret = pbl_led_set(STATUS_LED, 0U, 0U);
if (ret != 0) {
fprintf(stderr, "led: off failed (%d)\n", ret);
return ret;
}
printf("led: off\n");
pbl_sleep_ms(PERIOD_MS / 2);
}
printf("led: blinked %d times\n", BLINKS);
printf("Sample done\n");
return 0;
}
led: on
led: off
led: blinked 5 times
Sample done
Generated from PebbleOS 12b6c531f. This page is maintained in the pebbleos repository: docs/samples/drivers/led.md.