elementary serial print using the external IO breakout board and PL2303
main.cpp@6:bc8d140ac7bb, 2019-10-23 (annotated)
- Committer:
- matrixmike
- Date:
- Wed Oct 23 12:00:14 2019 +0000
- Revision:
- 6:bc8d140ac7bb
- Parent:
- 5:71c91969b507
- Child:
- 7:6be360dd949a
stream of chars
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
matrixmike | 0:782954b320bb | 1 | /* |
matrixmike | 0:782954b320bb | 2 | The MIT License (MIT) |
matrixmike | 0:782954b320bb | 3 | |
matrixmike | 0:782954b320bb | 4 | Copyright (c) 2016 British Broadcasting Corporation. |
matrixmike | 0:782954b320bb | 5 | This software is provided by Lancaster University by arrangement with the BBC. |
matrixmike | 0:782954b320bb | 6 | |
matrixmike | 0:782954b320bb | 7 | Permission is hereby granted, free of charge, to any person obtaining a |
matrixmike | 0:782954b320bb | 8 | copy of this software and associated documentation files (the "Software"), |
matrixmike | 0:782954b320bb | 9 | to deal in the Software without restriction, including without limitation |
matrixmike | 0:782954b320bb | 10 | the rights to use, copy, modify, merge, publish, distribute, sublicense, |
matrixmike | 0:782954b320bb | 11 | and/or sell copies of the Software, and to permit persons to whom the |
matrixmike | 0:782954b320bb | 12 | Software is furnished to do so, subject to the following conditions: |
matrixmike | 0:782954b320bb | 13 | |
matrixmike | 0:782954b320bb | 14 | The above copyright notice and this permission notice shall be included in |
matrixmike | 0:782954b320bb | 15 | all copies or substantial portions of the Software. |
matrixmike | 0:782954b320bb | 16 | |
matrixmike | 0:782954b320bb | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
matrixmike | 0:782954b320bb | 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
matrixmike | 0:782954b320bb | 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
matrixmike | 0:782954b320bb | 20 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
matrixmike | 0:782954b320bb | 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
matrixmike | 0:782954b320bb | 22 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
matrixmike | 0:782954b320bb | 23 | DEALINGS IN THE SOFTWARE. |
matrixmike | 0:782954b320bb | 24 | */ |
matrixmike | 5:71c91969b507 | 25 | #include "MicroBit.h" |
matrixmike | 5:71c91969b507 | 26 | MicroBit uBit; |
matrixmike | 5:71c91969b507 | 27 | MicroBitSerial serial(USBTX, USBRX); |
matrixmike | 5:71c91969b507 | 28 | int main() |
matrixmike | 5:71c91969b507 | 29 | { |
matrixmike | 5:71c91969b507 | 30 | uBit.init(); |
matrixmike | 5:71c91969b507 | 31 | serial.format(8,mbed::RawSerial::None,2); |
matrixmike | 6:bc8d140ac7bb | 32 | serial.baud(9600); |
matrixmike | 5:71c91969b507 | 33 | serial.redirect(MICROBIT_PIN_P1, MICROBIT_PIN_P2); // tx,rx |
matrixmike | 5:71c91969b507 | 34 | serial.send("A\r\n"); |
matrixmike | 5:71c91969b507 | 35 | for (int x = 0; x < 1000; x++) { |
matrixmike | 6:bc8d140ac7bb | 36 | serial.send("B"); // was serial.send("A\r\n"); |
matrixmike | 5:71c91969b507 | 37 | } |
matrixmike | 5:71c91969b507 | 38 | release_fiber(); |
matrixmike | 5:71c91969b507 | 39 | } |
matrixmike | 0:782954b320bb | 40 | |
matrixmike | 5:71c91969b507 | 41 | // ......... |
matrixmike | 5:71c91969b507 | 42 | //#include "MicroBit.h" |
matrixmike | 5:71c91969b507 | 43 | //#include "mbed.h" |
matrixmike | 5:71c91969b507 | 44 | /* |
matrixmike | 0:782954b320bb | 45 | Serial pc(USBTX, USBRX); |
matrixmike | 0:782954b320bb | 46 | MicroBit uBit; |
matrixmike | 5:71c91969b507 | 47 | MicroBitSerial serial(USBTX, USBRX); |
matrixmike | 0:782954b320bb | 48 | int main() |
matrixmike | 0:782954b320bb | 49 | { |
matrixmike | 4:c0f36c59d853 | 50 | Serial pc(USBTX, USBRX); |
matrixmike | 0:782954b320bb | 51 | // Initialise the micro:bit runtime. |
matrixmike | 0:782954b320bb | 52 | uBit.init(); |
matrixmike | 5:71c91969b507 | 53 | serial.baud(9600); |
matrixmike | 0:782954b320bb | 54 | for ( int x = 2; x < 14; x++) { |
matrixmike | 0:782954b320bb | 55 | pc.printf("Hello World on a Friday\n\r"); |
matrixmike | 1:c180896f50ce | 56 | pc.printf("Hello World on a %d Friday\n\r", x ); |
matrixmike | 1:c180896f50ce | 57 | pc.printf("Hello World on a %c Friday\n\r", '%' ); |
matrixmike | 5:71c91969b507 | 58 | uBit.display.scroll("HELLO WORLD! 2:)"); |
matrixmike | 0:782954b320bb | 59 | } |
matrixmike | 0:782954b320bb | 60 | |
matrixmike | 0:782954b320bb | 61 | // If main exits, there may still be other fibers running or registered event handlers etc. |
matrixmike | 0:782954b320bb | 62 | // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then |
matrixmike | 0:782954b320bb | 63 | // sit in the idle task forever, in a power efficient sleep. |
matrixmike | 0:782954b320bb | 64 | release_fiber(); |
matrixmike | 0:782954b320bb | 65 | } |
matrixmike | 5:71c91969b507 | 66 | */ |
matrixmike | 0:782954b320bb | 67 | // Print "Hello World" to the PC |
matrixmike | 0:782954b320bb | 68 | /* |
matrixmike | 0:782954b320bb | 69 | #include "mbed.h" |
matrixmike | 0:782954b320bb | 70 | |
matrixmike | 0:782954b320bb | 71 | Serial pc(USBTX, USBRX); |
matrixmike | 0:782954b320bb | 72 | |
matrixmike | 0:782954b320bb | 73 | int main() { |
matrixmike | 0:782954b320bb | 74 | pc.printf("Hello World\n"); |
matrixmike | 0:782954b320bb | 75 | } |
matrixmike | 0:782954b320bb | 76 | */ |