micorbit sample using the radio component to trasmit from Lancaster University.

Dependencies:   microbit

Committer:
haraldblab
Date:
Mon May 04 09:13:01 2020 +0000
Revision:
0:8c12e5b14b31
using microbit rad as transmitter

Who changed what in which revision?

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