Using C/C++, coding for MicroBit to count from 0 to 9 and then return to 0. Each change in number takes one second.

Dependencies:   microbit

Committer:
tsfarber
Date:
Tue Nov 26 04:43:28 2019 +0000
Revision:
0:b3cdb6213088
Tested and verified working

Who changed what in which revision?

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