![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
LOO C++ project
Dependencies: mbed text_to_speak_mbed GroveEarbudSensor
main.cpp@0:213bf9be9e9e, 2018-12-23 (annotated)
- Committer:
- EnSoka
- Date:
- Sun Dec 23 19:51:55 2018 +0000
- Revision:
- 0:213bf9be9e9e
Project LOO c++
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
EnSoka | 0:213bf9be9e9e | 1 | |
EnSoka | 0:213bf9be9e9e | 2 | #include "mbed.h" |
EnSoka | 0:213bf9be9e9e | 3 | |
EnSoka | 0:213bf9be9e9e | 4 | // Blinky |
EnSoka | 0:213bf9be9e9e | 5 | DigitalOut led(LED1); |
EnSoka | 0:213bf9be9e9e | 6 | |
EnSoka | 0:213bf9be9e9e | 7 | Serial pc(p9, p10); // tx, rx |
EnSoka | 0:213bf9be9e9e | 8 | |
EnSoka | 0:213bf9be9e9e | 9 | // Our sensor as an InterruptIn |
EnSoka | 0:213bf9be9e9e | 10 | InterruptIn sensor(D0); |
EnSoka | 0:213bf9be9e9e | 11 | |
EnSoka | 0:213bf9be9e9e | 12 | // Grove Earbud Sensor include |
EnSoka | 0:213bf9be9e9e | 13 | #include "GroveEarbudSensor.h" |
EnSoka | 0:213bf9be9e9e | 14 | |
EnSoka | 0:213bf9be9e9e | 15 | // callback for receiving heartrate values |
EnSoka | 0:213bf9be9e9e | 16 | void heartrateCallback(float heartrate,void *data) { |
EnSoka | 0:213bf9be9e9e | 17 | printf("Callback: heartrate = %.1f\r\n",heartrate); |
EnSoka | 0:213bf9be9e9e | 18 | } |
EnSoka | 0:213bf9be9e9e | 19 | |
EnSoka | 0:213bf9be9e9e | 20 | int main() |
EnSoka | 0:213bf9be9e9e | 21 | { |
EnSoka | 0:213bf9be9e9e | 22 | /* |
EnSoka | 0:213bf9be9e9e | 23 | // announce |
EnSoka | 0:213bf9be9e9e | 24 | printf("Grove Earbud Sensor Example v1.0.0\r\n"); |
EnSoka | 0:213bf9be9e9e | 25 | |
EnSoka | 0:213bf9be9e9e | 26 | // allocate the earbud sensor |
EnSoka | 0:213bf9be9e9e | 27 | printf("Allocating earbud sensor instance...\r\n"); |
EnSoka | 0:213bf9be9e9e | 28 | GroveEarbudSensor earbud(&sensor); |
EnSoka | 0:213bf9be9e9e | 29 | |
EnSoka | 0:213bf9be9e9e | 30 | // register our callback function |
EnSoka | 0:213bf9be9e9e | 31 | printf("registering callback...\r\n"); |
EnSoka | 0:213bf9be9e9e | 32 | earbud.registerCallback(heartrateCallback); |
EnSoka | 0:213bf9be9e9e | 33 | |
EnSoka | 0:213bf9be9e9e | 34 | // begin main loop |
EnSoka | 0:213bf9be9e9e | 35 | printf("Beginning main loop...\r\n"); |
EnSoka | 0:213bf9be9e9e | 36 | while (true) { |
EnSoka | 0:213bf9be9e9e | 37 | // blink... |
EnSoka | 0:213bf9be9e9e | 38 | led = !led; |
EnSoka | 0:213bf9be9e9e | 39 | wait(0.5); |
EnSoka | 0:213bf9be9e9e | 40 | |
EnSoka | 0:213bf9be9e9e | 41 | // we can also call directly |
EnSoka | 0:213bf9be9e9e | 42 | //printf("Direct: heartrate = %.1f\r\n",earbud.getHeartRate()); |
EnSoka | 0:213bf9be9e9e | 43 | }*/ |
EnSoka | 0:213bf9be9e9e | 44 | /* pc.baud(19200); |
EnSoka | 0:213bf9be9e9e | 45 | pc.printf("Hello World\n");*/ |
EnSoka | 0:213bf9be9e9e | 46 | |
EnSoka | 0:213bf9be9e9e | 47 | // announce |
EnSoka | 0:213bf9be9e9e | 48 | printf("Grove Earbud Sensor Example v1.0.0\r\n"); |
EnSoka | 0:213bf9be9e9e | 49 | |
EnSoka | 0:213bf9be9e9e | 50 | // allocate the earbud sensor |
EnSoka | 0:213bf9be9e9e | 51 | printf("Allocating earbud sensor instance...\r\n"); |
EnSoka | 0:213bf9be9e9e | 52 | GroveEarbudSensor earbud(&sensor); |
EnSoka | 0:213bf9be9e9e | 53 | |
EnSoka | 0:213bf9be9e9e | 54 | // register our callback function |
EnSoka | 0:213bf9be9e9e | 55 | printf("registering callback...\r\n"); |
EnSoka | 0:213bf9be9e9e | 56 | earbud.registerCallback(heartrateCallback); |
EnSoka | 0:213bf9be9e9e | 57 | |
EnSoka | 0:213bf9be9e9e | 58 | // begin main loop |
EnSoka | 0:213bf9be9e9e | 59 | printf("Beginning main loop...\r\n"); |
EnSoka | 0:213bf9be9e9e | 60 | while (true) { |
EnSoka | 0:213bf9be9e9e | 61 | // blink... |
EnSoka | 0:213bf9be9e9e | 62 | led = !led; |
EnSoka | 0:213bf9be9e9e | 63 | wait(0.5); |
EnSoka | 0:213bf9be9e9e | 64 | |
EnSoka | 0:213bf9be9e9e | 65 | // we can also call directly |
EnSoka | 0:213bf9be9e9e | 66 | //printf("Direct: heartrate = %.1f\r\n",earbud.getHeartRate()); |
EnSoka | 0:213bf9be9e9e | 67 | } |
EnSoka | 0:213bf9be9e9e | 68 | } |