Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLENano2_AD_Serial by
main.cpp
- Committer:
- electricbaka
- Date:
- 2018-09-20
- Revision:
- 3:01f92b787f26
- Parent:
- 2:2b070a0b5e17
File content as of revision 3:01f92b787f26:
/*
*
* BLE Nano2 : USB Serial Communication
*
* http://jellyware.jp/kurage/
*
*/
//------------------------------------------------------------
//Include Header Files
//------------------------------------------------------------
#include "mbed.h"
//------------------------------------------------------------
//Definition
//------------------------------------------------------------
#define ANALOG_IN_PIN1 P0_5
#define TICKER_TIME 1000 //1000[us] = 1[ms]
//HeartRate
int timer_num = 0;
int threshold_v = 650;
int threshold_t = 300;
//======================================================================
//onTimeout
//======================================================================
void m_status_check_handle(void)
{
timer_num ++;
}
//------------------------------------------------------------
//Object generation
//------------------------------------------------------------
AnalogIn ANALOG1(ANALOG_IN_PIN1);
Serial pc(P0_29, P0_30);
int main(void)
{
pc.baud(9600);
char str[10];
//Timer Setting [us]
Ticker ticker;
ticker.attach_us(m_status_check_handle, TICKER_TIME);
int timer_ms;
while(1)
{
float s = ANALOG1;
uint16_t value = s * 1024;
//---------------------------------------------------------------------------------------------
//Detect HeartRate Peak
//---------------------------------------------------------------------------------------------
timer_ms = TICKER_TIME/1000 * timer_num;
if(value >= threshold_v && timer_ms > threshold_t)
{
//clear timer_num
timer_num = 0;
sprintf(str, "%d\r\n", timer_ms);
pc.printf(str);
}
}
}
