Skip to content

Commit 9adbae5

Browse files
committed
samples: Added tone_doremi sample
Add a tone_doremi sample to demonstrate how to sounding with tone API Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1 parent 631017c commit 9adbae5

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

samples/tone_doremi/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
# get value of NORMALIZED_BOARD_TARGET early
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE} COMPONENTS yaml boards)
7+
8+
if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../variants/${NORMALIZED_BOARD_TARGET}/${NORMALIZED_BOARD_TARGET}_${BOARD_REVISION}.overlay)
9+
set(DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/../../variants/${NORMALIZED_BOARD_TARGET}/${NORMALIZED_BOARD_TARGET}_${BOARD_REVISION}.overlay)
10+
elseif (EXISTS ${CMAKE_CURRENT_LIST_DIR}/../../variants/${NORMALIZED_BOARD_TARGET}/${NORMALIZED_BOARD_TARGET}.overlay)
11+
set(DTC_OVERLAY_FILE ${CMAKE_CURRENT_LIST_DIR}/../../variants/${NORMALIZED_BOARD_TARGET}/${NORMALIZED_BOARD_TARGET}.overlay)
12+
endif()
13+
14+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
15+
project(tone_doremi)
16+
17+
target_sources(app PRIVATE src/app.cpp)
18+
19+
zephyr_compile_options(-Wno-unused-variable -Wno-comment)

samples/tone_doremi/README.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.. _tone_doremi:
2+
3+
Tone DoReMi
4+
###########
5+
6+
Overview
7+
********
8+
9+
Use tone to play the scale.
10+
Play Do, Re, Mi on D4 pin, then Fa, So, La on D5 pin.
11+
12+
Building and Running
13+
********************
14+
15+
Build and flash tone_doremi sample as follows,
16+
17+
.. code-block:: sh
18+
19+
$> west build -p -b arduino_nano_33_ble samples/tone_doremi/
20+
21+
$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac

samples/tone_doremi/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_ARDUINO_API=y
2+
CONFIG_ARDUINO_MAX_TONES=2

samples/tone_doremi/src/app.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2026 TOKITA Hiroshi
5+
*/
6+
7+
#include <Arduino.h>
8+
#include "zephyrSerial.h"
9+
10+
#define NOTE_C4 262
11+
#define NOTE_D4 294
12+
#define NOTE_E4 330
13+
#define NOTE_F4 349
14+
#define NOTE_G4 392
15+
#define NOTE_A4 440
16+
17+
void setup() {
18+
Serial.begin(115200);
19+
}
20+
21+
void loop() {
22+
Serial.println("Do@D4");
23+
tone(D4, NOTE_C4, 1000);
24+
delay(1000);
25+
Serial.println("Re@D4");
26+
tone(D4, NOTE_D4, 1000);
27+
delay(1000);
28+
Serial.println("Mi@D4 - Infinity");
29+
tone(D4, NOTE_E4, 0);
30+
delay(1000);
31+
Serial.println("Fa@D5");
32+
tone(D5, NOTE_F4, 1000);
33+
delay(1000);
34+
Serial.println("So@D5");
35+
tone(D5, NOTE_G4, 1000);
36+
delay(1000);
37+
Serial.println("La@D5 - Infinity");
38+
tone(D5, NOTE_A4, 0);
39+
40+
while(true);
41+
}
42+

0 commit comments

Comments
 (0)