Skip to content

Commit b32d822

Browse files
committed
samples: Added fade sample
Added a fade sample to demonstrate how to use analogWrite API Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@fujitsu.com>
1 parent 1948a8c commit b32d822

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

samples/fade/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
set(DTC_OVERLAY_FILE $ENV{ZEPHYR_BASE}/../modules/lib/Arduino-Zephyr-API/variants/${BOARD}/${BOARD}.overlay)
6+
7+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
8+
project(fade)
9+
10+
target_sources(app PRIVATE src/app.cpp)
11+
12+
zephyr_compile_options(-Wno-unused-variable -Wno-comment)

samples/fade/README.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. _fade:
2+
3+
Fade
4+
####
5+
6+
Overview
7+
********
8+
9+
The Fade sample gradually increases/decreases the voltage of the output pin.
10+
When connecting the LED to the output pin, the LED blinks gradually.
11+
12+
Building and Running
13+
********************
14+
15+
Build and flash Fade sample as follows,
16+
17+
```sh
18+
$> west build -p -b arduino_nano_33_ble samples/basic/fade/ -DZEPHYR_EXTRA_MODULES=/home/$USER/zephyrproject/modules/lib/Arduino-Core-Zephyr
19+
20+
$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac
21+
```

samples/fade/prj.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_CPLUSPLUS=y
2+
CONFIG_ARDUINO_API=y
3+
CONFIG_GPIO=y
4+
CONFIG_PWM=y

samples/fade/src/app.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
#include <Arduino.h>
6+
#include "zephyrSerial.h"
7+
8+
const int led = 3; // PWM output pin.
9+
const int increments = 5;
10+
const int wait_ms = 10;
11+
12+
void setup() {
13+
/* Pin that use as the PWM output must not configure by pinMode() */
14+
}
15+
16+
void loop() {
17+
int value = 0;
18+
while (value < 256) {
19+
analogWrite(led, value);
20+
value += increments;
21+
delay(wait_ms);
22+
}
23+
24+
value = 255;
25+
while (value >= 0) {
26+
analogWrite(led, value);
27+
value -= increments;
28+
delay(wait_ms);
29+
}
30+
}

0 commit comments

Comments
 (0)