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:00:04 2016 +0100
Revision:
0:28eb63dc225a
Update to git: v2.0.0-rc4-5-g115d5a8

Who changed what in which revision?

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