Heart rate monitoring system design using FRDM K64F and MIT App Inventor II
Dependencies: ESP8266 GroveEarbudSensor mbed
Fork of Heart-rate-monitor by
main.cpp@4:df7309612854, 2014-09-26 (annotated)
- Committer:
- ansond
- Date:
- Fri Sep 26 02:39:13 2014 +0000
- Revision:
- 4:df7309612854
- Parent:
- 0:1358c23ecb2e
- Child:
- 5:f1b55ff3cda0
switched to BufferedSerial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:1358c23ecb2e | 1 | /* Copyright C2014 ARM, MIT License |
ansond | 0:1358c23ecb2e | 2 | * |
ansond | 0:1358c23ecb2e | 3 | * Author: Doug Anson (doug.anson@arm.com) |
ansond | 0:1358c23ecb2e | 4 | * |
ansond | 0:1358c23ecb2e | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 0:1358c23ecb2e | 6 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 0:1358c23ecb2e | 7 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 0:1358c23ecb2e | 8 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 0:1358c23ecb2e | 9 | * furnished to do so, subject to the following conditions: |
ansond | 0:1358c23ecb2e | 10 | * |
ansond | 0:1358c23ecb2e | 11 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 0:1358c23ecb2e | 12 | * substantial portions of the Software. |
ansond | 0:1358c23ecb2e | 13 | * |
ansond | 0:1358c23ecb2e | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 0:1358c23ecb2e | 15 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 0:1358c23ecb2e | 16 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 0:1358c23ecb2e | 17 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 0:1358c23ecb2e | 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 0:1358c23ecb2e | 19 | */ |
ansond | 0:1358c23ecb2e | 20 | |
ansond | 0:1358c23ecb2e | 21 | #include "mbed.h" |
ansond | 0:1358c23ecb2e | 22 | |
ansond | 0:1358c23ecb2e | 23 | // Console |
ansond | 4:df7309612854 | 24 | #include "BufferedSerial.h" |
ansond | 4:df7309612854 | 25 | BufferedSerial pc(USBTX,USBRX); |
ansond | 0:1358c23ecb2e | 26 | |
ansond | 0:1358c23ecb2e | 27 | // Blinky |
ansond | 0:1358c23ecb2e | 28 | DigitalOut led(LED1); |
ansond | 0:1358c23ecb2e | 29 | |
ansond | 0:1358c23ecb2e | 30 | // Our sensor as an InterruptIn |
ansond | 0:1358c23ecb2e | 31 | InterruptIn sensor(D0); |
ansond | 0:1358c23ecb2e | 32 | |
ansond | 0:1358c23ecb2e | 33 | // Grove Earbud Sensor include |
ansond | 0:1358c23ecb2e | 34 | #include "GroveEarbudSensor.h" |
ansond | 0:1358c23ecb2e | 35 | |
ansond | 0:1358c23ecb2e | 36 | // callback for receiving heartrate values |
ansond | 0:1358c23ecb2e | 37 | void heartrateCallback(float heartrate,void *data) { |
ansond | 0:1358c23ecb2e | 38 | pc.printf("Callback: heartrate = %.1f\r\n",heartrate); |
ansond | 0:1358c23ecb2e | 39 | } |
ansond | 0:1358c23ecb2e | 40 | |
ansond | 0:1358c23ecb2e | 41 | int main() |
ansond | 0:1358c23ecb2e | 42 | { |
ansond | 0:1358c23ecb2e | 43 | // announce |
ansond | 0:1358c23ecb2e | 44 | pc.printf("Grove Earbud Sensor Example v1.0.0\r\n"); |
ansond | 0:1358c23ecb2e | 45 | |
ansond | 0:1358c23ecb2e | 46 | // allocate the earbud sensor |
ansond | 0:1358c23ecb2e | 47 | pc.printf("Allocating earbud sensor instance...\r\n"); |
ansond | 0:1358c23ecb2e | 48 | GroveEarbudSensor earbud(&sensor); |
ansond | 0:1358c23ecb2e | 49 | |
ansond | 0:1358c23ecb2e | 50 | // register our callback function |
ansond | 0:1358c23ecb2e | 51 | pc.printf("registering callback...\r\n"); |
ansond | 0:1358c23ecb2e | 52 | earbud.registerCallback(heartrateCallback); |
ansond | 0:1358c23ecb2e | 53 | |
ansond | 0:1358c23ecb2e | 54 | // begin main loop |
ansond | 0:1358c23ecb2e | 55 | pc.printf("Beginning main loop...\r\n"); |
ansond | 0:1358c23ecb2e | 56 | while (true) { |
ansond | 0:1358c23ecb2e | 57 | // blink... |
ansond | 0:1358c23ecb2e | 58 | led = !led; |
ansond | 0:1358c23ecb2e | 59 | wait(0.5); |
ansond | 0:1358c23ecb2e | 60 | |
ansond | 0:1358c23ecb2e | 61 | // we can also call directly |
ansond | 0:1358c23ecb2e | 62 | //pc.printf("Direct: heartrate = %.1f\r\n",earbud.getHeartRate()); |
ansond | 0:1358c23ecb2e | 63 | } |
ansond | 0:1358c23ecb2e | 64 | } |