|
| 1 | +.. _blinky-tone-sample: |
| 2 | + |
| 3 | +Blinky Tone |
| 4 | +############ |
| 5 | + |
| 6 | +Overview |
| 7 | +******** |
| 8 | + |
| 9 | +This Arduino Blinky sample blinks an LED forever using the `tone` and `noTone`. |
| 10 | + |
| 11 | +Requirements |
| 12 | +************ |
| 13 | + |
| 14 | +Your board must: |
| 15 | + |
| 16 | +#. Have an LED connected via a GPIO pin (these are called "User LEDs" on many of |
| 17 | + Zephyr's :ref:`boards`). |
| 18 | +#. Have the LED configured using the ``led0`` devicetree alias. |
| 19 | + |
| 20 | +Building and Running |
| 21 | +******************** |
| 22 | + |
| 23 | +Build and flash Blinky as follows, |
| 24 | + |
| 25 | +```sh |
| 26 | +$> west build -p -b arduino_nano_33_ble samples/basic/blinky_tone/ -DZEPHYR_EXTRA_MODULES=/home/$USER/zephyrproject/modules/lib/Arduino-Core-Zephyr |
| 27 | +
|
| 28 | +$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac |
| 29 | +``` |
| 30 | + |
| 31 | +After flashing, the LED starts to blink. If a runtime error occurs, the sample |
| 32 | +exits without printing to the console. |
| 33 | + |
| 34 | +Adding board support |
| 35 | +******************** |
| 36 | + |
| 37 | +To add support for your board, add something like this to your devicetree: |
| 38 | + |
| 39 | +.. code-block:: DTS |
| 40 | +
|
| 41 | + / { |
| 42 | + aliases { |
| 43 | + led0 = &myled0; |
| 44 | + }; |
| 45 | +
|
| 46 | + leds { |
| 47 | + compatible = "gpio-leds"; |
| 48 | + myled0: led_0 { |
| 49 | + gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; |
| 50 | + }; |
| 51 | + }; |
| 52 | + }; |
| 53 | +
|
| 54 | +The above sets your board's ``led0`` alias to use pin 13 on GPIO controller |
| 55 | +``gpio0``. The pin flags :c:macro:`GPIO_ACTIVE_HIGH` mean the LED is on when |
| 56 | +the pin is set to its high state, and off when the pin is in its low state. |
| 57 | + |
| 58 | +Tips: |
| 59 | + |
| 60 | +- See :dtcompatible:`gpio-leds` for more information on defining GPIO-based LEDs |
| 61 | + in devicetree. |
| 62 | + |
| 63 | +- If you're not sure what to do, check the devicetrees for supported boards which |
| 64 | + use the same SoC as your target. See :ref:`get-devicetree-outputs` for details. |
| 65 | + |
| 66 | +- See :zephyr_file:`include/zephyr/dt-bindings/gpio/gpio.h` for the flags you can use |
| 67 | + in devicetree. |
| 68 | + |
| 69 | +- If the LED is built in to your board hardware, the alias should be defined in |
| 70 | + your :ref:`BOARD.dts file <devicetree-in-out-files>`. Otherwise, you can |
| 71 | + define one in a :ref:`devicetree overlay <set-devicetree-overlays>`. |
0 commit comments