Michael Hewitt / microbit-hello-world2

Dependencies:   microbit

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*
00002 The MIT License (MIT)
00003 
00004 Copyright (c) 2016 British Broadcasting Corporation.
00005 This software is provided by Lancaster University by arrangement with the BBC.
00006 
00007 Permission is hereby granted, free of charge, to any person obtaining a
00008 copy of this software and associated documentation files (the "Software"),
00009 to deal in the Software without restriction, including without limitation
00010 the rights to use, copy, modify, merge, publish, distribute, sublicense,
00011 and/or sell copies of the Software, and to permit persons to whom the
00012 Software is furnished to do so, subject to the following conditions:
00013 
00014 The above copyright notice and this permission notice shall be included in
00015 all copies or substantial portions of the Software.
00016 
00017 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00018 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00019 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00020 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00021 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00022 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00023 DEALINGS IN THE SOFTWARE.
00024 */
00025 #include "MicroBit.h"
00026 MicroBit uBit;
00027 MicroBitSerial serial(USBTX, USBRX);
00028 int main()
00029 {
00030     uBit.init();
00031     /*    int sendChar(char c);
00032         int send(ManagedString s);
00033      */
00034     int c;
00035 
00036     c = 'c';
00037     serial.format(8,mbed::RawSerial::None,2);
00038     serial.baud(1200);  // changed to transmit to Brother EP44 
00039     serial.redirect(MICROBIT_PIN_P1, MICROBIT_PIN_P2);  // tx,rx
00040     serial.send("A\r\n");
00041 //    c=uBit.serial.read(ASYNC);
00042     for (int x = 0; x < 100; x++) {
00043         serial.send("B");  // was serial.send("A\r\n");
00044         serial.send(char(c));
00045 //       serial.send(s);
00046 //       c=uBit.serial.read(ASYNC);
00047     }
00048     release_fiber();
00049 }
00050 
00051 // .........
00052 //#include "MicroBit.h"
00053 //#include "mbed.h"
00054 /*
00055 Serial pc(USBTX, USBRX);
00056 MicroBit uBit;
00057 MicroBitSerial serial(USBTX, USBRX);
00058 int main()
00059 {
00060     Serial pc(USBTX, USBRX);
00061     // Initialise the micro:bit runtime.
00062     uBit.init();
00063       serial.baud(9600);
00064     for ( int x = 2; x < 14; x++) {
00065     pc.printf("Hello World on a Friday\n\r");
00066     pc.printf("Hello World on a %d Friday\n\r", x );
00067     pc.printf("Hello World on a %c Friday\n\r", '%' );
00068     uBit.display.scroll("HELLO WORLD! 2:)");
00069     }
00070 
00071     // If main exits, there may still be other fibers running or registered event handlers etc.
00072     // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then
00073     // sit in the idle task forever, in a power efficient sleep.
00074     release_fiber();
00075 }
00076 */
00077 // Print "Hello World" to the PC
00078 /*
00079 #include "mbed.h"
00080 
00081 Serial pc(USBTX, USBRX);
00082 
00083 int main() {
00084     pc.printf("Hello World\n");
00085 }
00086 */