
7
//will change the state of LED
unsigned
char
counter
;
unsigned
long
temp
[
21
];
unsigned
long
sub
;
bool data_effect
=
true
;
unsigned
int
heart_rate
;
//the measurement result of heart rate
const
int
max_heartpluse_duty
=
2000
;
//you can change it follow your
system's request.
//2000 meams 2 seconds. System return error
//if the duty overtrip 2 second.
void
setup
()
{
pinMode
(
LED
,
OUTPUT
);
Serial
.
begin
(
9600
);
Serial
.
println
(
"Please ready your chest belt."
);
delay
(
5000
);
arrayInit
();
Serial
.
println
(
"Heart rate test begin."
);
attachInterrupt
(
0
,
interrupt
,
RISING
);
//set interrupt 0,digital port
2
}
void
loop
()
{
digitalWrite
(
LED
,
led_state
);
//Update the state of the indicator
}
/*Function: calculate the heart rate*/
void
sum
()
{
if
(
data_effect
)
{
heart_rate
=
1200000
/(
temp
[
20
]-
temp
[
0
]);
//60*20*1000/20_total_time
Serial
.
(
"Heart_rate_is:\t"
);
Serial
.
println
(
heart_rate
);
}
data_effect
=
1
;
//sign bit
}
/*Function: Interrupt service routine.Get the sigal from the external
interrupt*/
void
interrupt
()
{
temp
[
counter
]=
millis
();
Serial
.
println
(
counter
,
DEC
);
Serial
.
println
(
temp
[
counter
]);
Содержание Grove 101020033
Страница 2: ...2 Document Revision History Revision Date Author Description 1 0 Sep 21 2015 Victor He Create file ...
Страница 6: ...3 2 Features Low power consumption Convenient to use High sensitivity Fully RoHS compliant ...
Страница 8: ...5 4 Application Ideas Heart rate monitor ...
Страница 13: ...10 6 Resources Grove Ear clip Heart Rate Sensor Demo code ...
Страница 14: ...11 7 Support If you have questions or other better design ideas you can go to our forum or wish to discuss ...