An example of how to us the micro:bit DAL's abstraction. This is a one-way translation of the microbit-samples repository on GitHub. Please don't try to push changes here, instead push them to the source repo at https://github.com/lancaster-university/microbit-samples

Dependencies:   microbit

Committer:
LancasterUniversity
Date:
Wed Jul 13 16:06:24 2016 +0100
Revision:
0:6f5b145e8427
Update to git: v2.0.0-rc4-5-g115d5a8

Who changed what in which revision?

UserRevisionLine numberNew contents of line
LancasterUniversity 0:6f5b145e8427 1 /*
LancasterUniversity 0:6f5b145e8427 2 The MIT License (MIT)
LancasterUniversity 0:6f5b145e8427 3
LancasterUniversity 0:6f5b145e8427 4 Copyright (c) 2016 British Broadcasting Corporation.
LancasterUniversity 0:6f5b145e8427 5 This software is provided by Lancaster University by arrangement with the BBC.
LancasterUniversity 0:6f5b145e8427 6
LancasterUniversity 0:6f5b145e8427 7 Permission is hereby granted, free of charge, to any person obtaining a
LancasterUniversity 0:6f5b145e8427 8 copy of this software and associated documentation files (the "Software"),
LancasterUniversity 0:6f5b145e8427 9 to deal in the Software without restriction, including without limitation
LancasterUniversity 0:6f5b145e8427 10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
LancasterUniversity 0:6f5b145e8427 11 and/or sell copies of the Software, and to permit persons to whom the
LancasterUniversity 0:6f5b145e8427 12 Software is furnished to do so, subject to the following conditions:
LancasterUniversity 0:6f5b145e8427 13
LancasterUniversity 0:6f5b145e8427 14 The above copyright notice and this permission notice shall be included in
LancasterUniversity 0:6f5b145e8427 15 all copies or substantial portions of the Software.
LancasterUniversity 0:6f5b145e8427 16
LancasterUniversity 0:6f5b145e8427 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
LancasterUniversity 0:6f5b145e8427 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
LancasterUniversity 0:6f5b145e8427 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
LancasterUniversity 0:6f5b145e8427 20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LancasterUniversity 0:6f5b145e8427 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
LancasterUniversity 0:6f5b145e8427 22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
LancasterUniversity 0:6f5b145e8427 23 DEALINGS IN THE SOFTWARE.
LancasterUniversity 0:6f5b145e8427 24 */
LancasterUniversity 0:6f5b145e8427 25
LancasterUniversity 0:6f5b145e8427 26 #include "MicroBit.h"
LancasterUniversity 0:6f5b145e8427 27
LancasterUniversity 0:6f5b145e8427 28 MicroBit uBit;
LancasterUniversity 0:6f5b145e8427 29
LancasterUniversity 0:6f5b145e8427 30 int main()
LancasterUniversity 0:6f5b145e8427 31 {
LancasterUniversity 0:6f5b145e8427 32 // Initialise the micro:bit runtime.
LancasterUniversity 0:6f5b145e8427 33 uBit.init();
LancasterUniversity 0:6f5b145e8427 34 uBit.radio.enable();
LancasterUniversity 0:6f5b145e8427 35
LancasterUniversity 0:6f5b145e8427 36 while(1)
LancasterUniversity 0:6f5b145e8427 37 {
LancasterUniversity 0:6f5b145e8427 38 if (uBit.buttonA.isPressed())
LancasterUniversity 0:6f5b145e8427 39 uBit.radio.datagram.send("1");
LancasterUniversity 0:6f5b145e8427 40
LancasterUniversity 0:6f5b145e8427 41 else if (uBit.buttonB.isPressed())
LancasterUniversity 0:6f5b145e8427 42 uBit.radio.datagram.send("2");
LancasterUniversity 0:6f5b145e8427 43
LancasterUniversity 0:6f5b145e8427 44 uBit.sleep(100);
LancasterUniversity 0:6f5b145e8427 45 }
LancasterUniversity 0:6f5b145e8427 46
LancasterUniversity 0:6f5b145e8427 47 }
LancasterUniversity 0:6f5b145e8427 48