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.
main.cpp@1:476ea02888de, 2021-03-19 (annotated)
- Committer:
- sshms
- Date:
- Fri Mar 19 05:42:27 2021 +0000
- Revision:
- 1:476ea02888de
- Parent:
- 0:fbd1445cf962
added comments
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| sshms | 0:fbd1445cf962 | 1 | /* |
| sshms | 0:fbd1445cf962 | 2 | The MIT License (MIT) |
| sshms | 0:fbd1445cf962 | 3 | |
| sshms | 0:fbd1445cf962 | 4 | Copyright (c) 2016 British Broadcasting Corporation. |
| sshms | 0:fbd1445cf962 | 5 | This software is provided by Lancaster University by arrangement with the BBC. |
| sshms | 0:fbd1445cf962 | 6 | |
| sshms | 0:fbd1445cf962 | 7 | Permission is hereby granted, free of charge, to any person obtaining a |
| sshms | 0:fbd1445cf962 | 8 | copy of this software and associated documentation files (the "Software"), |
| sshms | 0:fbd1445cf962 | 9 | to deal in the Software without restriction, including without limitation |
| sshms | 0:fbd1445cf962 | 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| sshms | 0:fbd1445cf962 | 11 | and/or sell copies of the Software, and to permit persons to whom the |
| sshms | 0:fbd1445cf962 | 12 | Software is furnished to do so, subject to the following conditions: |
| sshms | 0:fbd1445cf962 | 13 | |
| sshms | 0:fbd1445cf962 | 14 | The above copyright notice and this permission notice shall be included in |
| sshms | 0:fbd1445cf962 | 15 | all copies or substantial portions of the Software. |
| sshms | 0:fbd1445cf962 | 16 | |
| sshms | 0:fbd1445cf962 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| sshms | 0:fbd1445cf962 | 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| sshms | 0:fbd1445cf962 | 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| sshms | 0:fbd1445cf962 | 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| sshms | 0:fbd1445cf962 | 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| sshms | 0:fbd1445cf962 | 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| sshms | 0:fbd1445cf962 | 23 | DEALINGS IN THE SOFTWARE. |
| sshms | 0:fbd1445cf962 | 24 | */ |
| sshms | 0:fbd1445cf962 | 25 | |
| sshms | 0:fbd1445cf962 | 26 | #include "MicroBit.h" |
| sshms | 0:fbd1445cf962 | 27 | |
| sshms | 0:fbd1445cf962 | 28 | MicroBit uBit; |
| sshms | 0:fbd1445cf962 | 29 | |
| sshms | 0:fbd1445cf962 | 30 | int main() |
| sshms | 0:fbd1445cf962 | 31 | { |
| sshms | 0:fbd1445cf962 | 32 | // Initialise the micro:bit runtime. |
| sshms | 0:fbd1445cf962 | 33 | uBit.init(); |
| sshms | 0:fbd1445cf962 | 34 | |
| sshms | 0:fbd1445cf962 | 35 | // Insert your code here! |
| sshms | 0:fbd1445cf962 | 36 | while (true){ |
| sshms | 1:476ea02888de | 37 | // Intro Message |
| sshms | 0:fbd1445cf962 | 38 | if (uBit.buttonA.isPressed()) |
| sshms | 0:fbd1445cf962 | 39 | { |
| sshms | 0:fbd1445cf962 | 40 | uBit.display.scroll("Touch and hold the processor and press button B to measure"); |
| sshms | 0:fbd1445cf962 | 41 | |
| sshms | 0:fbd1445cf962 | 42 | } |
| sshms | 1:476ea02888de | 43 | // Display DANGER! if temp greater than 37.8, else display SAFE! |
| sshms | 0:fbd1445cf962 | 44 | if (uBit.buttonB.isPressed()) |
| sshms | 0:fbd1445cf962 | 45 | { |
| sshms | 0:fbd1445cf962 | 46 | if (uBit.thermometer.getTemperature() > 37.8) |
| sshms | 0:fbd1445cf962 | 47 | { |
| sshms | 0:fbd1445cf962 | 48 | uBit.display.scroll(uBit.thermometer.getTemperature()); |
| sshms | 0:fbd1445cf962 | 49 | uBit.display.scroll("DANGER!"); |
| sshms | 0:fbd1445cf962 | 50 | } |
| sshms | 0:fbd1445cf962 | 51 | else |
| sshms | 0:fbd1445cf962 | 52 | { |
| sshms | 0:fbd1445cf962 | 53 | uBit.display.scroll(uBit.thermometer.getTemperature()); |
| sshms | 0:fbd1445cf962 | 54 | uBit.display.scroll("SAFE!"); |
| sshms | 0:fbd1445cf962 | 55 | } |
| sshms | 0:fbd1445cf962 | 56 | |
| sshms | 0:fbd1445cf962 | 57 | } |
| sshms | 0:fbd1445cf962 | 58 | } |
| sshms | 0:fbd1445cf962 | 59 | |
| sshms | 0:fbd1445cf962 | 60 | |
| sshms | 0:fbd1445cf962 | 61 | // If main exits, there may still be other fibers running or registered event handlers etc. |
| sshms | 0:fbd1445cf962 | 62 | // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then |
| sshms | 0:fbd1445cf962 | 63 | // sit in the idle task forever, in a power efficient sleep. |
| sshms | 0:fbd1445cf962 | 64 | release_fiber(); |
| sshms | 0:fbd1445cf962 | 65 | } |
| sshms | 0:fbd1445cf962 | 66 |