Sample program illustrating the use of the GroveEarbudSensor library
Dependencies: GroveEarbudSensor mbed
main.cpp
00001 /* Copyright C2014 ARM, MIT License 00002 * 00003 * Author: Doug Anson (doug.anson@arm.com) 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 00006 * and associated documentation files the "Software", to deal in the Software without restriction, 00007 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 00008 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 00009 * furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included in all copies or 00012 * substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 00015 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00016 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 00017 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00018 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00019 */ 00020 00021 #include "mbed.h" 00022 00023 // Blinky 00024 DigitalOut led(LED1); 00025 00026 // Our sensor as an InterruptIn 00027 InterruptIn sensor(D0); 00028 00029 // Grove Earbud Sensor include 00030 #include "GroveEarbudSensor.h" 00031 00032 // callback for receiving heartrate values 00033 void heartrateCallback(float heartrate,void *data) { 00034 printf("Callback: heartrate = %.1f\r\n",heartrate); 00035 } 00036 00037 int main() 00038 { 00039 // announce 00040 printf("Grove Earbud Sensor Example v1.0.0\r\n"); 00041 00042 // allocate the earbud sensor 00043 printf("Allocating earbud sensor instance...\r\n"); 00044 GroveEarbudSensor earbud(&sensor); 00045 00046 // register our callback function 00047 printf("registering callback...\r\n"); 00048 earbud.registerCallback(heartrateCallback); 00049 00050 // begin main loop 00051 printf("Beginning main loop...\r\n"); 00052 while (true) { 00053 // blink... 00054 led = !led; 00055 wait(0.5); 00056 00057 // we can also call directly 00058 //printf("Direct: heartrate = %.1f\r\n",earbud.getHeartRate()); 00059 } 00060 }
Generated on Fri Jul 15 2022 12:20:15 by 1.7.2