Skip to content

Commit 08f6289

Browse files
committed
Add first example
Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
1 parent db4ab9d commit 08f6289

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

examples/NonReg/PulseIn/PulseIn.ino

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
pulseIn
3+
4+
This sketch allows to test pulseIn() and pulseInLong() functions.
5+
6+
A PWM signal is generated on 'pwm' pin and then measures are performed on
7+
'in' pin for the HIGH and LOW state.
8+
The min and max value for both are displayed on the Serial console.
9+
10+
Creation 15 Sep 2017
11+
by Frederic Pillon
12+
13+
This example code is in the public domain.
14+
15+
https://www.arduino.cc/en/Reference/PulseIn
16+
*/
17+
18+
19+
// Use pulseInLong()?
20+
#define USE_PULSEINLONG 1
21+
22+
static uint32_t pwm = 9;
23+
static uint32_t in = 4;
24+
static uint32_t state = HIGH;
25+
26+
void setup() {
27+
pinMode(in, INPUT);
28+
Serial.begin(115200);
29+
analogWrite(pwm, 127);
30+
}
31+
static uint32_t min_duration_low = (uint32_t)(-1);
32+
static uint32_t max_duration_low = 0;
33+
static uint32_t min_duration_high = (uint32_t)(-1);
34+
static uint32_t max_duration_high = 0;
35+
#if USE_PULSEINLONG
36+
static uint32_t min_durationLong_low = (uint32_t)(-1);
37+
static uint32_t max_durationLong_low = 0;
38+
static uint32_t min_durationLong_high = (uint32_t)(-1);
39+
static uint32_t max_durationLong_high = 0;
40+
#endif
41+
42+
void loop() {
43+
uint32_t duration = 0;
44+
duration = pulseIn(in, state);
45+
#if USE_PULSEINLONG
46+
uint32_t durationLong = 0;
47+
durationLong = pulseInLong(in, state);
48+
#endif
49+
if (state == HIGH) {
50+
Serial.print("PulseIn HIGH state duration:");
51+
min_duration_high=min(min_duration_high,duration);
52+
max_duration_high=max(max_duration_high,duration);
53+
Serial.print(" min= ");
54+
Serial.print(min_duration_high);
55+
Serial.print(" max= ");
56+
Serial.print(max_duration_high);
57+
#if USE_PULSEINLONG
58+
min_durationLong_high=min(min_durationLong_high,durationLong);
59+
max_durationLong_high=max(max_durationLong_high,durationLong);
60+
Serial.print(" min (long)= ");
61+
Serial.print(min_durationLong_high);
62+
Serial.print(" max (long)= ");
63+
Serial.print(max_durationLong_high);
64+
#endif
65+
state = LOW;
66+
}
67+
else {
68+
Serial.print("PulseIn LOW state duration:");
69+
min_duration_low=min(min_duration_low,duration);
70+
max_duration_low=max(max_duration_low,duration);
71+
Serial.print(" min= ");
72+
Serial.print(min_duration_low);
73+
Serial.print(" max= ");
74+
Serial.print(max_duration_low);
75+
#if USE_PULSEINLONG
76+
min_durationLong_low=min(min_durationLong_low,durationLong);
77+
max_durationLong_low=max(max_durationLong_low,durationLong);
78+
Serial.print(" min (long)= ");
79+
Serial.print(min_durationLong_low);
80+
Serial.print(" max (long)= ");
81+
Serial.print(max_durationLong_low);
82+
#endif
83+
state = HIGH;
84+
}
85+
Serial.println();
86+
delay(1000);
87+
}

library.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=STM32duino Examples
2+
version=1.0.0
3+
author=fpistm
4+
maintainer=stm32duino
5+
sentence=Provides several examples for the Arduino core for STM32 MCUs.
6+
paragraph=Arduino STM32 core, libraries and example are available here: https://github.com/stm32duino
7+
category=Other
8+
url=https://github.com/stm32duino/STM32Examples
9+
architectures=stm32

src/STM32Examples.h

Whitespace-only changes.

0 commit comments

Comments
 (0)