elementary serial print using the external IO breakout board and PL2303

Dependencies:   microbit

Committer:
matrixmike
Date:
Wed Oct 23 12:20:49 2019 +0000
Revision:
7:6be360dd949a
Parent:
6:bc8d140ac7bb
Child:
8:49fe8894d28d
revising char and string knowledge

Who changed what in which revision?

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