Git Product home page Git Product logo

blinky_example's Introduction

.. zephyr:code-sample:: pwm-blinky
   :name: PWM Blinky
   :relevant-api: pwm_interface

   Blink an LED using the PWM API.

Overview

This application blinks an LED using the :ref:`PWM API <pwm_api>`. See :zephyr:code-sample:`blinky` for a GPIO-based sample.

The LED starts blinking at a 1 Hz frequency. The frequency doubles every 4 seconds until it reaches 128 Hz. The frequency will then be halved every 4 seconds until it returns to 1 Hz, completing a single blinking cycle. This faster-then-slower blinking cycle then repeats forever.

Some PWM hardware cannot set the PWM period to 1 second to achieve the blinking frequency of 1 Hz. This sample calibrates itself to what the hardware supports at startup. The maximum PWM period is decreased appropriately until a value supported by the hardware is found.

Requirements

The board must have an LED connected to a PWM output channel. The PWM controlling this LED must be configured using the pwm_led0 :ref:`devicetree <dt-guide>` alias, usually in the :ref:`BOARD.dts file <devicetree-in-out-files>`.

Wiring

No additional wiring is necessary if pwm_led0 refers to hardware that is already connected to an LED on the board.

In these other cases, however, manual wiring is necessary:

Board Wiring
:ref:`nucleo_f401re_board` connect PWM2 (PA0) to an LED
:ref:`nucleo_l476rg_board` connect PWM2 (PA0) to an LED
:ref:`stm32f4_disco_board` connect PWM2 (PA0) to an LED
:ref:`nucleo_f302r8_board` connect PWM2 (PA0) to an LED
:ref:`nucleo_f103rb_board` connect PWM1 (PA8) to an LED
:ref:`nucleo_wb55rg_board` connect PWM1 (PA8) to an LED
:ref:`esp32_devkitc_wroom` connect GPIO2 to an LED
:ref:`esp32s2_saola` connect GPIO2 to an LED
:ref:`esp32c3_devkitm` connect GPIO2 to an LED

Building and Running

To build and flash this sample for the :ref:`nrf52840dk_nrf52840`:

.. zephyr-app-commands::
   :zephyr-app: samples/basic/blinky_pwm
   :board: nrf52840dk/nrf52840
   :goals: build flash
   :compact:

Change nrf52840dk/nrf52840 appropriately for other supported boards.

After flashing, the sample starts blinking the LED as described above. It also prints information to the board's console.

blinky_example's People

Contributors

mootseeker avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.