-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use `tone` and `noTone` functions to blink led at 1hz with duty cycle 50% on any digital pin Signed-off-by: Ayush Singh <ayushdevel1325@gmail.com>
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
cmake_minimum_required(VERSION 3.20.0) | ||
|
||
cmake_path(SET ZephyrBase $ENV{ZEPHYR_BASE}) | ||
set(DTC_OVERLAY_FILE ${ZephyrBase}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay) | ||
|
||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
project(blinky) | ||
|
||
target_sources(app PRIVATE src/main.cpp) | ||
|
||
zephyr_compile_options(-Wno-unused-variable -Wno-comment) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
.. _blinky-tone-sample: | ||
|
||
Blinky Tone | ||
############ | ||
|
||
Overview | ||
******** | ||
|
||
This Arduino Blinky sample blinks an LED forever using the `tone` and `noTone`. | ||
|
||
Requirements | ||
************ | ||
|
||
Your board must: | ||
|
||
#. Have an LED connected via a GPIO pin (these are called "User LEDs" on many of | ||
Zephyr's :ref:`boards`). | ||
#. Have the LED configured using the ``led0`` devicetree alias. | ||
|
||
Building and Running | ||
******************** | ||
|
||
Build and flash Blinky as follows, | ||
|
||
```sh | ||
$> west build -p -b arduino_nano_33_ble samples/basic/blinky_tone/ -DZEPHYR_EXTRA_MODULES=/home/$USER/zephyrproject/modules/lib/Arduino-Core-Zephyr | ||
$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac | ||
``` | ||
|
||
After flashing, the LED starts to blink. If a runtime error occurs, the sample | ||
exits without printing to the console. | ||
|
||
Adding board support | ||
******************** | ||
|
||
To add support for your board, add something like this to your devicetree: | ||
|
||
.. code-block:: DTS | ||
/ { | ||
aliases { | ||
led0 = &myled0; | ||
}; | ||
leds { | ||
compatible = "gpio-leds"; | ||
myled0: led_0 { | ||
gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; | ||
}; | ||
}; | ||
}; | ||
The above sets your board's ``led0`` alias to use pin 13 on GPIO controller | ||
``gpio0``. The pin flags :c:macro:`GPIO_ACTIVE_HIGH` mean the LED is on when | ||
the pin is set to its high state, and off when the pin is in its low state. | ||
|
||
Tips: | ||
|
||
- See :dtcompatible:`gpio-leds` for more information on defining GPIO-based LEDs | ||
in devicetree. | ||
|
||
- If you're not sure what to do, check the devicetrees for supported boards which | ||
use the same SoC as your target. See :ref:`get-devicetree-outputs` for details. | ||
|
||
- See :zephyr_file:`include/zephyr/dt-bindings/gpio/gpio.h` for the flags you can use | ||
in devicetree. | ||
|
||
- If the LED is built in to your board hardware, the alias should be defined in | ||
your :ref:`BOARD.dts file <devicetree-in-out-files>`. Otherwise, you can | ||
define one in a :ref:`devicetree overlay <set-devicetree-overlays>`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
CONFIG_GPIO=y | ||
CONFIG_CPLUSPLUS=y | ||
CONFIG_ARDUINO_API=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/* Blink inbuilt LED with tone */ | ||
|
||
#include <Arduino.h> | ||
|
||
void setup() { | ||
pinMode(LED_BUILTIN, OUTPUT); | ||
} | ||
|
||
void loop() { | ||
tone(LED_BUILTIN, 1, 10000); | ||
delay(15000); | ||
tone(LED_BUILTIN, 1); | ||
delay(10000); | ||
noTone(LED_BUILTIN); | ||
delay(5000); | ||
} |