From 779e25bc7d4f53b74e34fe81d3b1371b100b5802 Mon Sep 17 00:00:00 2001 From: Alexandre Abadie Date: Mon, 21 Oct 2019 21:34:59 +0200 Subject: [PATCH] tests/sys_arduino_analog: add test application The goal of this application is to test the analogRead and analogWrite Arduino function --- tests/sys_arduino_analog/Makefile | 15 +++++++++++++++ tests/sys_arduino_analog/arduino-test.sketch | 15 +++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/sys_arduino_analog/Makefile create mode 100644 tests/sys_arduino_analog/arduino-test.sketch diff --git a/tests/sys_arduino_analog/Makefile b/tests/sys_arduino_analog/Makefile new file mode 100644 index 0000000000..061d9111d3 --- /dev/null +++ b/tests/sys_arduino_analog/Makefile @@ -0,0 +1,15 @@ +BOARD ?= arduino-zero + +include ../Makefile.tests_common + +LED_PIN ?= 3 + +USEMODULE += arduino + +# Features used by Arduino analogRead/analogWrite functions are required +FEATURES_REQUIRED += arduino_pwm +FEATURES_REQUIRED += periph_adc + +CFLAGS += -DLED_PIN=$(LED_PIN) + +include $(RIOTBASE)/Makefile.include diff --git a/tests/sys_arduino_analog/arduino-test.sketch b/tests/sys_arduino_analog/arduino-test.sketch new file mode 100644 index 0000000000..43475fb27a --- /dev/null +++ b/tests/sys_arduino_analog/arduino-test.sketch @@ -0,0 +1,15 @@ +// Example sketch given in analogWrite documentation +// https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/ + +int ledPin = LED_PIN; // LED connected to digital pin 3 by default +int analogPin = 1; // potentiometer connected to analog pin 1 +int val = 0; // variable to store the read value + +void setup() { + pinMode(ledPin, OUTPUT); // sets the pin as output +} + +void loop() { + val = analogRead(analogPin); // read the input pin + analogWrite(ledPin, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255 +}