File tree 4 files changed +67
-0
lines changed
4 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
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 (analog_input)
9
+
10
+ target_sources (app PRIVATE src/main.cpp)
11
+ zephyr_compile_options(-Wno-unused-variable -Wno-comment )
Original file line number Diff line number Diff line change
1
+ .. _analog_input :
2
+
3
+ Analog Input
4
+ ############
5
+
6
+ Overview
7
+ ********
8
+
9
+ The analog_input sample blinks the LED with control of the period
10
+ by the voltage of the input pin.
11
+ Inputting high voltage to blink the LED slowly.
12
+ Blink the LED fast on input voltage is low.
13
+ When the input is 0V, LED light.
14
+
15
+ Building and Running
16
+ ********************
17
+
18
+ Build and flash analog_input sample as follows,
19
+
20
+ ```sh
21
+ $> west build -p -b arduino_nano_33_ble sample/analog_input/
22
+
23
+ $> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac
24
+ ` ``
Original file line number Diff line number Diff line change
1
+ CONFIG_ADC=y
2
+ CONFIG_ARDUINO_API=y
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2022 TOKITA Hiroshi <[email protected] >
3
+ *
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ #include < Arduino.h>
8
+
9
+ const int analog_input = A0; // select the input pin for the potentiometer
10
+ const int ledPin = LED_BUILTIN; // select the pin for the LED
11
+ const float wait_factor = 1 .f;
12
+
13
+ void setup () {
14
+ pinMode (ledPin, OUTPUT);
15
+ }
16
+
17
+ void loop () {
18
+ int value = 0 ;
19
+
20
+ value = analogRead (analog_input);
21
+
22
+ /* Blinks slowly when the input voltage is high */
23
+
24
+ digitalWrite (ledPin, HIGH);
25
+ delay (value * wait_factor);
26
+
27
+ digitalWrite (ledPin, LOW);
28
+ delay (value * wait_factor);
29
+ }
30
+
You can’t perform that action at this time.
0 commit comments