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@0:41d3bf4a7ce2, 2020-05-10 (annotated)
- Committer:
- haraldblab
- Date:
- Sun May 10 14:03:16 2020 +0000
- Revision:
- 0:41d3bf4a7ce2
- Child:
- 1:040ce5e7720a
Inventor's kit experiment two: using an ldr and analog inputs.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| haraldblab | 0:41d3bf4a7ce2 | 1 | /* |
| haraldblab | 0:41d3bf4a7ce2 | 2 | * Inventor's kit for micor:bit |
| haraldblab | 0:41d3bf4a7ce2 | 3 | * Experiment 1: Say "Hello"to the BBC micro:bit |
| haraldblab | 0:41d3bf4a7ce2 | 4 | */ |
| haraldblab | 0:41d3bf4a7ce2 | 5 | |
| haraldblab | 0:41d3bf4a7ce2 | 6 | #include "MicroBit.h" |
| haraldblab | 0:41d3bf4a7ce2 | 7 | |
| haraldblab | 0:41d3bf4a7ce2 | 8 | MicroBit uBit; |
| haraldblab | 0:41d3bf4a7ce2 | 9 | MicroBitImage sun("255,0,255, 0,255\n0,255,255,255,0\n255,255,255,255,255\n0,255,255,255,0\n255,0,255,0,255\n"); |
| haraldblab | 0:41d3bf4a7ce2 | 10 | MicroBitImage moon("255,255,255,0,0\n0,255,255,255,0\n0,0,255,255,0\n0,255,255,255,0\n255,255,255,0,0\n"); |
| haraldblab | 0:41d3bf4a7ce2 | 11 | // using p0 as analog pin |
| haraldblab | 0:41d3bf4a7ce2 | 12 | int main() |
| haraldblab | 0:41d3bf4a7ce2 | 13 | { |
| haraldblab | 0:41d3bf4a7ce2 | 14 | // Initialise the micro:bit runtime. |
| haraldblab | 0:41d3bf4a7ce2 | 15 | uBit.init(); |
| haraldblab | 0:41d3bf4a7ce2 | 16 | |
| haraldblab | 0:41d3bf4a7ce2 | 17 | MicroBitPin P0(MICROBIT_ID_IO_P0, MICROBIT_PIN_P0, PIN_CAPABILITY_ALL); |
| haraldblab | 0:41d3bf4a7ce2 | 18 | |
| haraldblab | 0:41d3bf4a7ce2 | 19 | // loop |
| haraldblab | 0:41d3bf4a7ce2 | 20 | while(1) |
| haraldblab | 0:41d3bf4a7ce2 | 21 | { |
| haraldblab | 0:41d3bf4a7ce2 | 22 | if (P0.getAnalogValue() >= 512) // P0 is a value in the range of 0 - 1024 |
| haraldblab | 0:41d3bf4a7ce2 | 23 | uBit.display.print(sun); |
| haraldblab | 0:41d3bf4a7ce2 | 24 | else |
| haraldblab | 0:41d3bf4a7ce2 | 25 | uBit.display.print(moon); |
| haraldblab | 0:41d3bf4a7ce2 | 26 | } |
| haraldblab | 0:41d3bf4a7ce2 | 27 | |
| haraldblab | 0:41d3bf4a7ce2 | 28 | } |
| haraldblab | 0:41d3bf4a7ce2 | 29 |