pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • PebbleOS
  • Mobile App
  • Examples
  • Index 01
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

PebbleOS

  • Overview
  • Start here
    • Getting started guide
  • Pebble Firmware
    • Overview
    • Playground
    • Application SDK
  • Development
    • The pbl CLI
    • Build system
    • Samples
      • Kernel
      • Subsystems
      • Drivers
      • Third-party
      • Rust
      • Benchmarks
    • Emulator and simulator
    • Testing
    • Debugging
    • Conventions
  • System
    • Architecture overview
    • Kernel
    • Drivers
    • Subsystems
    • Libraries
    • Third-party
  • Hardware
    • Boards
    • Board Add-ons
    • Programmers
  • Community
    • Contribution Guidelines
  • Reference
    • Reference
    • Kconfig options

LED: Blinking

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.

Run:

pbl samples samples/drivers/led

Boards:

every board

Sources

src/main.c
#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;
}

Output

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.

Overview

  • Sources
  • Output