Skip to content

Commit ba77581

Browse files
committed
samples: add arduino_core samples
Add arduino_core samples Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent 4c5be07 commit ba77581

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1077
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(analog_input)
7+
8+
target_sources(app PRIVATE src/main.cpp)
9+
zephyr_compile_options(-Wno-unused-variable -Wno-comment)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
```
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_ADC=y
2+
CONFIG_ARDUINO_API=y
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
sample:
2+
name: Arduino Analog Input sample
3+
4+
common:
5+
tags:
6+
- arduino_core
7+
required_snippets:
8+
- arduino_core
9+
platform_allow:
10+
- arduino_mkrzero/samd21g18a
11+
- arduino_nano_33_ble/nrf52840
12+
- arduino_nano_33_ble/nrf52840/sense
13+
- arduino_nano_33_iot/samd21g18a
14+
- beagleconnect_freedom/cc1352p7
15+
- cc3220sf_launchxl/cc3220sf
16+
- nrf52840dk/nrf52840
17+
- nrf9160dk/nrf9160
18+
- rpi_pico/rp2040
19+
20+
tests:
21+
sample.arduino_core.analog_impot.build:
22+
build_only: true
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(attach_interrupt)
7+
8+
target_sources(app PRIVATE src/main.cpp)
9+
10+
zephyr_compile_options(-Wno-unused-variable -Wno-comment)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.. _attach_interrupt-sample:
2+
3+
AttachInterrupt
4+
######
5+
6+
Overview
7+
********
8+
9+
This sample demonstrates how to use attachInterrupt API.
10+
11+
Building and Running
12+
********************
13+
14+
Build and flash attachInterrupt sample as follows,
15+
16+
```sh
17+
$> west build -p -b arduino_nano_33_ble samples/basic/attach_interrupt/ -DZEPHYR_EXTRA_MODULES=/home/$USER/zephyrproject/modules/lib/Arduino-Core-Zephyr
18+
19+
$> west flash --bossac=/home/$USER/.arduino15/packages/arduino/tools/bossac/1.9.1-arduino2/bossac
20+
```
21+
22+
Turn on the LED by detecting interrupts. And Turn off the next interrupt.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ARDUINO_API=y
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
sample:
2+
name: Attach Interrupt sample
3+
4+
common:
5+
tags:
6+
- arduino_core
7+
required_snippets:
8+
- arduino_core
9+
platform_allow:
10+
- arduino_mkrzero/samd21g18a
11+
- arduino_nano_33_ble/nrf52840
12+
- arduino_nano_33_ble/nrf52840/sense
13+
- arduino_nano_33_iot/samd21g18a
14+
- beagleconnect_freedom/cc1352p7
15+
- cc3220sf_launchxl/cc3220sf
16+
- nrf52840dk/nrf52840
17+
- nrf9160dk/nrf9160
18+
- rpi_pico/rp2040
19+
20+
tests:
21+
sample.arduino_core.attach_interrupt.build:
22+
build_only: true
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 pin_size_t ledPin = LED_BUILTIN;
10+
const pin_size_t interruptPin = 2;
11+
PinStatus state = LOW;
12+
13+
void blink() {
14+
state = (state == LOW) ? HIGH : LOW;
15+
digitalWrite(ledPin, state);
16+
}
17+
18+
void setup() {
19+
pinMode(ledPin, OUTPUT);
20+
pinMode(interruptPin, INPUT_PULLUP);
21+
attachInterrupt(interruptPin, blink, CHANGE);
22+
}
23+
24+
void loop() {
25+
}

0 commit comments

Comments
 (0)