microbit digital read test based on Lancaster University runtime

Dependencies:   microbit

Fork of microbit-hello-world by BBC

Committer:
coocox_paul
Date:
Mon Sep 19 03:40:12 2016 +0000
Revision:
1:2beebd57f1dc
Parent:
0:0041f35b0c4c
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
LancasterUniversity 0:0041f35b0c4c 1 /*
LancasterUniversity 0:0041f35b0c4c 2 The MIT License (MIT)
LancasterUniversity 0:0041f35b0c4c 3
LancasterUniversity 0:0041f35b0c4c 4 Copyright (c) 2016 British Broadcasting Corporation.
LancasterUniversity 0:0041f35b0c4c 5 This software is provided by Lancaster University by arrangement with the BBC.
LancasterUniversity 0:0041f35b0c4c 6
LancasterUniversity 0:0041f35b0c4c 7 Permission is hereby granted, free of charge, to any person obtaining a
LancasterUniversity 0:0041f35b0c4c 8 copy of this software and associated documentation files (the "Software"),
LancasterUniversity 0:0041f35b0c4c 9 to deal in the Software without restriction, including without limitation
LancasterUniversity 0:0041f35b0c4c 10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
LancasterUniversity 0:0041f35b0c4c 11 and/or sell copies of the Software, and to permit persons to whom the
LancasterUniversity 0:0041f35b0c4c 12 Software is furnished to do so, subject to the following conditions:
LancasterUniversity 0:0041f35b0c4c 13
LancasterUniversity 0:0041f35b0c4c 14 The above copyright notice and this permission notice shall be included in
LancasterUniversity 0:0041f35b0c4c 15 all copies or substantial portions of the Software.
LancasterUniversity 0:0041f35b0c4c 16
LancasterUniversity 0:0041f35b0c4c 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
LancasterUniversity 0:0041f35b0c4c 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
LancasterUniversity 0:0041f35b0c4c 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
LancasterUniversity 0:0041f35b0c4c 20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LancasterUniversity 0:0041f35b0c4c 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
LancasterUniversity 0:0041f35b0c4c 22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
LancasterUniversity 0:0041f35b0c4c 23 DEALINGS IN THE SOFTWARE.
LancasterUniversity 0:0041f35b0c4c 24 */
LancasterUniversity 0:0041f35b0c4c 25
LancasterUniversity 0:0041f35b0c4c 26 #include "MicroBit.h"
LancasterUniversity 0:0041f35b0c4c 27
LancasterUniversity 0:0041f35b0c4c 28 MicroBit uBit;
LancasterUniversity 0:0041f35b0c4c 29
LancasterUniversity 0:0041f35b0c4c 30 int main()
LancasterUniversity 0:0041f35b0c4c 31 {
coocox_paul 1:2beebd57f1dc 32 int v;
LancasterUniversity 0:0041f35b0c4c 33 // Initialise the micro:bit runtime.
LancasterUniversity 0:0041f35b0c4c 34 uBit.init();
LancasterUniversity 0:0041f35b0c4c 35
LancasterUniversity 0:0041f35b0c4c 36 // Insert your code here!
coocox_paul 1:2beebd57f1dc 37 uBit.display.scroll(":)");
coocox_paul 1:2beebd57f1dc 38
coocox_paul 1:2beebd57f1dc 39 while(1) {
coocox_paul 1:2beebd57f1dc 40
coocox_paul 1:2beebd57f1dc 41 v = uBit.io.P12.getDigitalValue();
coocox_paul 1:2beebd57f1dc 42 if(v) {
coocox_paul 1:2beebd57f1dc 43 uBit.display.scroll(":1");
coocox_paul 1:2beebd57f1dc 44 } else {
coocox_paul 1:2beebd57f1dc 45 uBit.display.scroll(":0");
coocox_paul 1:2beebd57f1dc 46 }
coocox_paul 1:2beebd57f1dc 47 uBit.sleep(2000);
coocox_paul 1:2beebd57f1dc 48 }
LancasterUniversity 0:0041f35b0c4c 49
LancasterUniversity 0:0041f35b0c4c 50 // If main exits, there may still be other fibers running or registered event handlers etc.
LancasterUniversity 0:0041f35b0c4c 51 // Simply release this fiber, which will mean we enter the scheduler. Worse case, we then
LancasterUniversity 0:0041f35b0c4c 52 // sit in the idle task forever, in a power efficient sleep.
LancasterUniversity 0:0041f35b0c4c 53 release_fiber();
LancasterUniversity 0:0041f35b0c4c 54 }
LancasterUniversity 0:0041f35b0c4c 55