elementary serial print using the external IO breakout board and PL2303
main.cpp@8:49fe8894d28d, 2019-10-23 (annotated)
- Committer:
- matrixmike
- Date:
- Wed Oct 23 12:46:37 2019 +0000
- Revision:
- 8:49fe8894d28d
- Parent:
- 7:6be360dd949a
- Child:
- 9:ea84b7a3e23f
after some poor tests - return to usable
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 | 8:49fe8894d28d | 31 | /* int sendChar(char c); |
matrixmike | 8:49fe8894d28d | 32 | int send(ManagedString s); |
matrixmike | 8:49fe8894d28d | 33 | */ |
matrixmike | 7:6be360dd949a | 34 | int c; |
matrixmike | 8:49fe8894d28d | 35 | |
matrixmike | 7:6be360dd949a | 36 | c = 'c'; |
matrixmike | 5:71c91969b507 | 37 | serial.format(8,mbed::RawSerial::None,2); |
matrixmike | 6:bc8d140ac7bb | 38 | serial.baud(9600); |
matrixmike | 5:71c91969b507 | 39 | serial.redirect(MICROBIT_PIN_P1, MICROBIT_PIN_P2); // tx,rx |
matrixmike | 5:71c91969b507 | 40 | serial.send("A\r\n"); |
matrixmike | 8:49fe8894d28d | 41 | // c=uBit.serial.read(ASYNC); |
matrixmike | 8:49fe8894d28d | 42 | for (int x = 0; x < 100; x++) { |
matrixmike | 8:49fe8894d28d | 43 | serial.send("B"); // was serial.send("A\r\n"); |
matrixmike | 7:6be360dd949a | 44 | serial.send(char(c)); |
matrixmike | 8:49fe8894d28d | 45 | // serial.send(s); |
matrixmike | 8:49fe8894d28d | 46 | // c=uBit.serial.read(ASYNC); |
matrixmike | 5:71c91969b507 | 47 | } |
matrixmike | 5:71c91969b507 | 48 | release_fiber(); |
matrixmike | 5:71c91969b507 | 49 | } |
matrixmike | 0:782954b320bb | 50 | |
matrixmike | 5:71c91969b507 | 51 | // ......... |
matrixmike | 5:71c91969b507 | 52 | //#include "MicroBit.h" |
matrixmike | 5:71c91969b507 | 53 | //#include "mbed.h" |
matrixmike | 5:71c91969b507 | 54 | /* |
matrixmike | 0:782954b320bb | 55 | Serial pc(USBTX, USBRX); |
matrixmike | 0:782954b320bb | 56 | MicroBit uBit; |
matrixmike | 5:71c91969b507 | 57 | MicroBitSerial serial(USBTX, USBRX); |
matrixmike | 0:782954b320bb | 58 | int main() |
matrixmike | 0:782954b320bb | 59 | { |
matrixmike | 4:c0f36c59d853 | 60 | Serial pc(USBTX, USBRX); |
matrixmike | 0:782954b320bb | 61 | // Initialise the micro:bit runtime. |
matrixmike | 0:782954b320bb | 62 | uBit.init(); |
matrixmike | 5:71c91969b507 | 63 | serial.baud(9600); |
matrixmike | 0:782954b320bb | 64 | for ( int x = 2; x < 14; x++) { |
matrixmike | 0:782954b320bb | 65 | pc.printf("Hello World on a Friday\n\r"); |
matrixmike | 1:c180896f50ce | 66 | pc.printf("Hello World on a %d Friday\n\r", x ); |
matrixmike | 1:c180896f50ce | 67 | pc.printf("Hello World on a %c Friday\n\r", '%' ); |
matrixmike | 5:71c91969b507 | 68 | uBit.display.scroll("HELLO WORLD! 2:)"); |
matrixmike | 0:782954b320bb | 69 | } |
matrixmike | 0:782954b320bb | 70 | |
matrixmike | 0:782954b320bb | 71 | // If main exits, there may still be other fibers running or registered event handlers etc. |
matrixmike | 0:782954b320bb | 72 | // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then |
matrixmike | 0:782954b320bb | 73 | // sit in the idle task forever, in a power efficient sleep. |
matrixmike | 0:782954b320bb | 74 | release_fiber(); |
matrixmike | 0:782954b320bb | 75 | } |
matrixmike | 5:71c91969b507 | 76 | */ |
matrixmike | 0:782954b320bb | 77 | // Print "Hello World" to the PC |
matrixmike | 0:782954b320bb | 78 | /* |
matrixmike | 0:782954b320bb | 79 | #include "mbed.h" |
matrixmike | 0:782954b320bb | 80 | |
matrixmike | 0:782954b320bb | 81 | Serial pc(USBTX, USBRX); |
matrixmike | 0:782954b320bb | 82 | |
matrixmike | 0:782954b320bb | 83 | int main() { |
matrixmike | 0:782954b320bb | 84 | pc.printf("Hello World\n"); |
matrixmike | 0:782954b320bb | 85 | } |
matrixmike | 0:782954b320bb | 86 | */ |