1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

tests/sys_arduino_analog: add test application

The goal of this application is to test the analogRead and analogWrite Arduino function
This commit is contained in:
Alexandre Abadie 2019-10-21 21:34:59 +02:00
parent e0f288421d
commit 779e25bc7d
No known key found for this signature in database
GPG Key ID: 1C919A403CAE1405
2 changed files with 30 additions and 0 deletions

View File

@ -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

View File

@ -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
}