Official Sheffield ARMBand micro:bit program

Committer:
MrBedfordVan
Date:
Mon Oct 17 12:41:20 2016 +0000
Revision:
0:b9164b348919
Official Sheffield ARMBand Micro:bit program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MrBedfordVan 0:b9164b348919 1 /*
MrBedfordVan 0:b9164b348919 2 The MIT License (MIT)
MrBedfordVan 0:b9164b348919 3
MrBedfordVan 0:b9164b348919 4 Copyright (c) 2016 British Broadcasting Corporation.
MrBedfordVan 0:b9164b348919 5 This software is provided by Lancaster University by arrangement with the BBC.
MrBedfordVan 0:b9164b348919 6
MrBedfordVan 0:b9164b348919 7 Permission is hereby granted, free of charge, to any person obtaining a
MrBedfordVan 0:b9164b348919 8 copy of this software and associated documentation files (the "Software"),
MrBedfordVan 0:b9164b348919 9 to deal in the Software without restriction, including without limitation
MrBedfordVan 0:b9164b348919 10 the rights to use, copy, modify, merge, publish, distribute, sublicense,
MrBedfordVan 0:b9164b348919 11 and/or sell copies of the Software, and to permit persons to whom the
MrBedfordVan 0:b9164b348919 12 Software is furnished to do so, subject to the following conditions:
MrBedfordVan 0:b9164b348919 13
MrBedfordVan 0:b9164b348919 14 The above copyright notice and this permission notice shall be included in
MrBedfordVan 0:b9164b348919 15 all copies or substantial portions of the Software.
MrBedfordVan 0:b9164b348919 16
MrBedfordVan 0:b9164b348919 17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
MrBedfordVan 0:b9164b348919 18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
MrBedfordVan 0:b9164b348919 19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
MrBedfordVan 0:b9164b348919 20 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
MrBedfordVan 0:b9164b348919 21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
MrBedfordVan 0:b9164b348919 22 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
MrBedfordVan 0:b9164b348919 23 DEALINGS IN THE SOFTWARE.
MrBedfordVan 0:b9164b348919 24 */
MrBedfordVan 0:b9164b348919 25
MrBedfordVan 0:b9164b348919 26 #ifndef MICROBIT_DISPLAY_H
MrBedfordVan 0:b9164b348919 27 #define MICROBIT_DISPLAY_H
MrBedfordVan 0:b9164b348919 28
MrBedfordVan 0:b9164b348919 29 #include "mbed.h"
MrBedfordVan 0:b9164b348919 30 #include "MicroBitConfig.h"
MrBedfordVan 0:b9164b348919 31 #include "ManagedString.h"
MrBedfordVan 0:b9164b348919 32 #include "MicroBitComponent.h"
MrBedfordVan 0:b9164b348919 33 #include "MicroBitImage.h"
MrBedfordVan 0:b9164b348919 34 #include "MicroBitFont.h"
MrBedfordVan 0:b9164b348919 35 #include "MicroBitMatrixMaps.h"
MrBedfordVan 0:b9164b348919 36 #include "MicroBitLightSensor.h"
MrBedfordVan 0:b9164b348919 37
MrBedfordVan 0:b9164b348919 38 /**
MrBedfordVan 0:b9164b348919 39 * Event codes raised by MicroBitDisplay
MrBedfordVan 0:b9164b348919 40 */
MrBedfordVan 0:b9164b348919 41 #define MICROBIT_DISPLAY_EVT_ANIMATION_COMPLETE 1
MrBedfordVan 0:b9164b348919 42 #define MICROBIT_DISPLAY_EVT_LIGHT_SENSE 2
MrBedfordVan 0:b9164b348919 43
MrBedfordVan 0:b9164b348919 44 //
MrBedfordVan 0:b9164b348919 45 // Internal constants
MrBedfordVan 0:b9164b348919 46 //
MrBedfordVan 0:b9164b348919 47 #define MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR 1
MrBedfordVan 0:b9164b348919 48 #define MICROBIT_DISPLAY_SPACING 1
MrBedfordVan 0:b9164b348919 49 #define MICROBIT_DISPLAY_GREYSCALE_BIT_DEPTH 8
MrBedfordVan 0:b9164b348919 50 #define MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS -255
MrBedfordVan 0:b9164b348919 51
MrBedfordVan 0:b9164b348919 52 enum AnimationMode {
MrBedfordVan 0:b9164b348919 53 ANIMATION_MODE_NONE,
MrBedfordVan 0:b9164b348919 54 ANIMATION_MODE_STOPPED,
MrBedfordVan 0:b9164b348919 55 ANIMATION_MODE_SCROLL_TEXT,
MrBedfordVan 0:b9164b348919 56 ANIMATION_MODE_PRINT_TEXT,
MrBedfordVan 0:b9164b348919 57 ANIMATION_MODE_SCROLL_IMAGE,
MrBedfordVan 0:b9164b348919 58 ANIMATION_MODE_ANIMATE_IMAGE,
MrBedfordVan 0:b9164b348919 59 ANIMATION_MODE_ANIMATE_IMAGE_WITH_CLEAR,
MrBedfordVan 0:b9164b348919 60 ANIMATION_MODE_PRINT_CHARACTER
MrBedfordVan 0:b9164b348919 61 };
MrBedfordVan 0:b9164b348919 62
MrBedfordVan 0:b9164b348919 63 enum DisplayMode {
MrBedfordVan 0:b9164b348919 64 DISPLAY_MODE_BLACK_AND_WHITE,
MrBedfordVan 0:b9164b348919 65 DISPLAY_MODE_GREYSCALE,
MrBedfordVan 0:b9164b348919 66 DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE
MrBedfordVan 0:b9164b348919 67 };
MrBedfordVan 0:b9164b348919 68
MrBedfordVan 0:b9164b348919 69 enum DisplayRotation {
MrBedfordVan 0:b9164b348919 70 MICROBIT_DISPLAY_ROTATION_0,
MrBedfordVan 0:b9164b348919 71 MICROBIT_DISPLAY_ROTATION_90,
MrBedfordVan 0:b9164b348919 72 MICROBIT_DISPLAY_ROTATION_180,
MrBedfordVan 0:b9164b348919 73 MICROBIT_DISPLAY_ROTATION_270
MrBedfordVan 0:b9164b348919 74 };
MrBedfordVan 0:b9164b348919 75
MrBedfordVan 0:b9164b348919 76 /**
MrBedfordVan 0:b9164b348919 77 * Class definition for MicroBitDisplay.
MrBedfordVan 0:b9164b348919 78 *
MrBedfordVan 0:b9164b348919 79 * A MicroBitDisplay represents the LED matrix array on the micro:bit.
MrBedfordVan 0:b9164b348919 80 */
MrBedfordVan 0:b9164b348919 81 class MicroBitDisplay : public MicroBitComponent
MrBedfordVan 0:b9164b348919 82 {
MrBedfordVan 0:b9164b348919 83 uint8_t width;
MrBedfordVan 0:b9164b348919 84 uint8_t height;
MrBedfordVan 0:b9164b348919 85 uint8_t brightness;
MrBedfordVan 0:b9164b348919 86 uint8_t strobeRow;
MrBedfordVan 0:b9164b348919 87 uint8_t rotation;
MrBedfordVan 0:b9164b348919 88 uint8_t mode;
MrBedfordVan 0:b9164b348919 89 uint8_t greyscaleBitMsk;
MrBedfordVan 0:b9164b348919 90 uint8_t timingCount;
MrBedfordVan 0:b9164b348919 91 uint32_t col_mask;
MrBedfordVan 0:b9164b348919 92
MrBedfordVan 0:b9164b348919 93 Timeout renderTimer;
MrBedfordVan 0:b9164b348919 94 PortOut *LEDMatrix;
MrBedfordVan 0:b9164b348919 95
MrBedfordVan 0:b9164b348919 96 //
MrBedfordVan 0:b9164b348919 97 // State used by all animation routines.
MrBedfordVan 0:b9164b348919 98 //
MrBedfordVan 0:b9164b348919 99
MrBedfordVan 0:b9164b348919 100 // The animation mode that's currently running (if any)
MrBedfordVan 0:b9164b348919 101 volatile AnimationMode animationMode;
MrBedfordVan 0:b9164b348919 102
MrBedfordVan 0:b9164b348919 103 // The time in milliseconds between each frame update.
MrBedfordVan 0:b9164b348919 104 uint16_t animationDelay;
MrBedfordVan 0:b9164b348919 105
MrBedfordVan 0:b9164b348919 106 // The time in milliseconds since the frame update.
MrBedfordVan 0:b9164b348919 107 uint16_t animationTick;
MrBedfordVan 0:b9164b348919 108
MrBedfordVan 0:b9164b348919 109 // Stop playback of any animations
MrBedfordVan 0:b9164b348919 110 void stopAnimation(int delay);
MrBedfordVan 0:b9164b348919 111
MrBedfordVan 0:b9164b348919 112 //
MrBedfordVan 0:b9164b348919 113 // State for scrollString() method.
MrBedfordVan 0:b9164b348919 114 // This is a surprisingly intricate method.
MrBedfordVan 0:b9164b348919 115 //
MrBedfordVan 0:b9164b348919 116 // The text being displayed.
MrBedfordVan 0:b9164b348919 117 ManagedString scrollingText;
MrBedfordVan 0:b9164b348919 118
MrBedfordVan 0:b9164b348919 119 // The index of the character currently being displayed.
MrBedfordVan 0:b9164b348919 120 uint16_t scrollingChar;
MrBedfordVan 0:b9164b348919 121
MrBedfordVan 0:b9164b348919 122 // The number of pixels the current character has been shifted on the display.
MrBedfordVan 0:b9164b348919 123 uint8_t scrollingPosition;
MrBedfordVan 0:b9164b348919 124
MrBedfordVan 0:b9164b348919 125 //
MrBedfordVan 0:b9164b348919 126 // State for printString() method.
MrBedfordVan 0:b9164b348919 127 //
MrBedfordVan 0:b9164b348919 128 // The text being displayed. NULL if no message is scheduled for playback.
MrBedfordVan 0:b9164b348919 129 // We *could* get some reuse in here with the scroll* variables above,
MrBedfordVan 0:b9164b348919 130 // but best to keep it clean in case kids try concurrent operation (they will!),
MrBedfordVan 0:b9164b348919 131 // given the small RAM overhead needed to maintain orthogonality.
MrBedfordVan 0:b9164b348919 132 ManagedString printingText;
MrBedfordVan 0:b9164b348919 133
MrBedfordVan 0:b9164b348919 134 // The index of the character currently being displayed.
MrBedfordVan 0:b9164b348919 135 uint16_t printingChar;
MrBedfordVan 0:b9164b348919 136
MrBedfordVan 0:b9164b348919 137 //
MrBedfordVan 0:b9164b348919 138 // State for scrollImage() method.
MrBedfordVan 0:b9164b348919 139 //
MrBedfordVan 0:b9164b348919 140 // The image being displayed.
MrBedfordVan 0:b9164b348919 141 MicroBitImage scrollingImage;
MrBedfordVan 0:b9164b348919 142
MrBedfordVan 0:b9164b348919 143 // The number of pixels the image has been shifted on the display.
MrBedfordVan 0:b9164b348919 144 int16_t scrollingImagePosition;
MrBedfordVan 0:b9164b348919 145
MrBedfordVan 0:b9164b348919 146 // The number of pixels the image is shifted on the display in each quantum.
MrBedfordVan 0:b9164b348919 147 int8_t scrollingImageStride;
MrBedfordVan 0:b9164b348919 148
MrBedfordVan 0:b9164b348919 149 // A pointer to an instance of light sensor, if in use
MrBedfordVan 0:b9164b348919 150 MicroBitLightSensor* lightSensor;
MrBedfordVan 0:b9164b348919 151
MrBedfordVan 0:b9164b348919 152 // Flag to indicate if image has been rendered to screen yet (or not)
MrBedfordVan 0:b9164b348919 153 bool scrollingImageRendered;
MrBedfordVan 0:b9164b348919 154
MrBedfordVan 0:b9164b348919 155 const MatrixMap &matrixMap;
MrBedfordVan 0:b9164b348919 156
MrBedfordVan 0:b9164b348919 157 // Internal methods to handle animation.
MrBedfordVan 0:b9164b348919 158
MrBedfordVan 0:b9164b348919 159 /**
MrBedfordVan 0:b9164b348919 160 * Periodic callback, that we use to perform any animations we have running.
MrBedfordVan 0:b9164b348919 161 */
MrBedfordVan 0:b9164b348919 162 void animationUpdate();
MrBedfordVan 0:b9164b348919 163
MrBedfordVan 0:b9164b348919 164 /**
MrBedfordVan 0:b9164b348919 165 * Called by the display in an interval determined by the brightness of the display, to give an impression
MrBedfordVan 0:b9164b348919 166 * of brightness.
MrBedfordVan 0:b9164b348919 167 */
MrBedfordVan 0:b9164b348919 168 void renderFinish();
MrBedfordVan 0:b9164b348919 169
MrBedfordVan 0:b9164b348919 170 /**
MrBedfordVan 0:b9164b348919 171 * Translates a bit mask to a bit mask suitable for the nrf PORT0 and PORT1.
MrBedfordVan 0:b9164b348919 172 * Brightness has two levels on, or off.
MrBedfordVan 0:b9164b348919 173 */
MrBedfordVan 0:b9164b348919 174 void render();
MrBedfordVan 0:b9164b348919 175
MrBedfordVan 0:b9164b348919 176 /**
MrBedfordVan 0:b9164b348919 177 * Renders the current image, and drops the fourth frame to allow for
MrBedfordVan 0:b9164b348919 178 * sensors that require the display to operate.
MrBedfordVan 0:b9164b348919 179 */
MrBedfordVan 0:b9164b348919 180 void renderWithLightSense();
MrBedfordVan 0:b9164b348919 181
MrBedfordVan 0:b9164b348919 182 /**
MrBedfordVan 0:b9164b348919 183 * Translates a bit mask into a timer interrupt that gives the appearence of greyscale.
MrBedfordVan 0:b9164b348919 184 */
MrBedfordVan 0:b9164b348919 185 void renderGreyscale();
MrBedfordVan 0:b9164b348919 186
MrBedfordVan 0:b9164b348919 187 /**
MrBedfordVan 0:b9164b348919 188 * Internal scrollText update method.
MrBedfordVan 0:b9164b348919 189 * Shift the screen image by one pixel to the left. If necessary, paste in the next char.
MrBedfordVan 0:b9164b348919 190 */
MrBedfordVan 0:b9164b348919 191 void updateScrollText();
MrBedfordVan 0:b9164b348919 192
MrBedfordVan 0:b9164b348919 193 /**
MrBedfordVan 0:b9164b348919 194 * Internal printText update method.
MrBedfordVan 0:b9164b348919 195 * Paste the next character in the string.
MrBedfordVan 0:b9164b348919 196 */
MrBedfordVan 0:b9164b348919 197 void updatePrintText();
MrBedfordVan 0:b9164b348919 198
MrBedfordVan 0:b9164b348919 199 /**
MrBedfordVan 0:b9164b348919 200 * Internal scrollImage update method.
MrBedfordVan 0:b9164b348919 201 * Paste the stored bitmap at the appropriate point.
MrBedfordVan 0:b9164b348919 202 */
MrBedfordVan 0:b9164b348919 203 void updateScrollImage();
MrBedfordVan 0:b9164b348919 204
MrBedfordVan 0:b9164b348919 205 /**
MrBedfordVan 0:b9164b348919 206 * Internal animateImage update method.
MrBedfordVan 0:b9164b348919 207 * Paste the stored bitmap at the appropriate point and stop on the last frame.
MrBedfordVan 0:b9164b348919 208 */
MrBedfordVan 0:b9164b348919 209 void updateAnimateImage();
MrBedfordVan 0:b9164b348919 210
MrBedfordVan 0:b9164b348919 211 /**
MrBedfordVan 0:b9164b348919 212 * Broadcasts an event onto the defult EventModel indicating that the
MrBedfordVan 0:b9164b348919 213 * current animation has completed.
MrBedfordVan 0:b9164b348919 214 */
MrBedfordVan 0:b9164b348919 215 void sendAnimationCompleteEvent();
MrBedfordVan 0:b9164b348919 216
MrBedfordVan 0:b9164b348919 217 /**
MrBedfordVan 0:b9164b348919 218 * Blocks the current fiber until the display is available (i.e. does not effect is being displayed).
MrBedfordVan 0:b9164b348919 219 * Animations are queued until their time to display.
MrBedfordVan 0:b9164b348919 220 */
MrBedfordVan 0:b9164b348919 221 void waitForFreeDisplay();
MrBedfordVan 0:b9164b348919 222
MrBedfordVan 0:b9164b348919 223 /**
MrBedfordVan 0:b9164b348919 224 * Blocks the current fiber until the current animation has finished.
MrBedfordVan 0:b9164b348919 225 * If the scheduler is not running, this call will essentially perform a spinning wait.
MrBedfordVan 0:b9164b348919 226 */
MrBedfordVan 0:b9164b348919 227 void fiberWait();
MrBedfordVan 0:b9164b348919 228
MrBedfordVan 0:b9164b348919 229 /**
MrBedfordVan 0:b9164b348919 230 * Enables or disables the display entirely, and releases the pins for other uses.
MrBedfordVan 0:b9164b348919 231 *
MrBedfordVan 0:b9164b348919 232 * @param enableDisplay true to enabled the display, or false to disable it.
MrBedfordVan 0:b9164b348919 233 */
MrBedfordVan 0:b9164b348919 234 void setEnable(bool enableDisplay);
MrBedfordVan 0:b9164b348919 235
MrBedfordVan 0:b9164b348919 236 public:
MrBedfordVan 0:b9164b348919 237 // The mutable bitmap buffer being rendered to the LED matrix.
MrBedfordVan 0:b9164b348919 238 MicroBitImage image;
MrBedfordVan 0:b9164b348919 239
MrBedfordVan 0:b9164b348919 240 /**
MrBedfordVan 0:b9164b348919 241 * Constructor.
MrBedfordVan 0:b9164b348919 242 *
MrBedfordVan 0:b9164b348919 243 * Create a software representation the micro:bit's 5x5 LED matrix.
MrBedfordVan 0:b9164b348919 244 * The display is initially blank.
MrBedfordVan 0:b9164b348919 245 *
MrBedfordVan 0:b9164b348919 246 * @param id The id the display should use when sending events on the MessageBus. Defaults to MICROBIT_ID_DISPLAY.
MrBedfordVan 0:b9164b348919 247 *
MrBedfordVan 0:b9164b348919 248 * @param map The mapping information that relates pin inputs/outputs to physical screen coordinates.
MrBedfordVan 0:b9164b348919 249 * Defaults to microbitMatrixMap, defined in MicroBitMatrixMaps.h.
MrBedfordVan 0:b9164b348919 250 *
MrBedfordVan 0:b9164b348919 251 * @code
MrBedfordVan 0:b9164b348919 252 * MicroBitDisplay display;
MrBedfordVan 0:b9164b348919 253 * @endcode
MrBedfordVan 0:b9164b348919 254 */
MrBedfordVan 0:b9164b348919 255 MicroBitDisplay(uint16_t id = MICROBIT_ID_DISPLAY, const MatrixMap &map = microbitMatrixMap);
MrBedfordVan 0:b9164b348919 256
MrBedfordVan 0:b9164b348919 257 /**
MrBedfordVan 0:b9164b348919 258 * Stops any currently running animation, and any that are waiting to be displayed.
MrBedfordVan 0:b9164b348919 259 */
MrBedfordVan 0:b9164b348919 260 void stopAnimation();
MrBedfordVan 0:b9164b348919 261
MrBedfordVan 0:b9164b348919 262 /**
MrBedfordVan 0:b9164b348919 263 * Frame update method, invoked periodically to strobe the display.
MrBedfordVan 0:b9164b348919 264 */
MrBedfordVan 0:b9164b348919 265 virtual void systemTick();
MrBedfordVan 0:b9164b348919 266
MrBedfordVan 0:b9164b348919 267 /**
MrBedfordVan 0:b9164b348919 268 * Prints the given character to the display, if it is not in use.
MrBedfordVan 0:b9164b348919 269 *
MrBedfordVan 0:b9164b348919 270 * @param c The character to display.
MrBedfordVan 0:b9164b348919 271 *
MrBedfordVan 0:b9164b348919 272 * @param delay Optional parameter - the time for which to show the character. Zero displays the character forever,
MrBedfordVan 0:b9164b348919 273 * or until the Displays next use.
MrBedfordVan 0:b9164b348919 274 *
MrBedfordVan 0:b9164b348919 275 * @return MICROBIT_OK, MICROBIT_BUSY is the screen is in use, or MICROBIT_INVALID_PARAMETER.
MrBedfordVan 0:b9164b348919 276 *
MrBedfordVan 0:b9164b348919 277 * @code
MrBedfordVan 0:b9164b348919 278 * display.printAsync('p');
MrBedfordVan 0:b9164b348919 279 * display.printAsync('p',100);
MrBedfordVan 0:b9164b348919 280 * @endcode
MrBedfordVan 0:b9164b348919 281 */
MrBedfordVan 0:b9164b348919 282 int printCharAsync(char c, int delay = 0);
MrBedfordVan 0:b9164b348919 283
MrBedfordVan 0:b9164b348919 284 /**
MrBedfordVan 0:b9164b348919 285 * Prints the given ManagedString to the display, one character at a time.
MrBedfordVan 0:b9164b348919 286 * Returns immediately, and executes the animation asynchronously.
MrBedfordVan 0:b9164b348919 287 *
MrBedfordVan 0:b9164b348919 288 * @param s The string to display.
MrBedfordVan 0:b9164b348919 289 *
MrBedfordVan 0:b9164b348919 290 * @param delay The time to delay between characters, in milliseconds. Must be > 0.
MrBedfordVan 0:b9164b348919 291 * Defaults to: MICROBIT_DEFAULT_PRINT_SPEED.
MrBedfordVan 0:b9164b348919 292 *
MrBedfordVan 0:b9164b348919 293 * @return MICROBIT_OK, or MICROBIT_INVALID_PARAMETER.
MrBedfordVan 0:b9164b348919 294 *
MrBedfordVan 0:b9164b348919 295 * @code
MrBedfordVan 0:b9164b348919 296 * display.printAsync("abc123",400);
MrBedfordVan 0:b9164b348919 297 * @endcode
MrBedfordVan 0:b9164b348919 298 */
MrBedfordVan 0:b9164b348919 299 int printAsync(ManagedString s, int delay = MICROBIT_DEFAULT_PRINT_SPEED);
MrBedfordVan 0:b9164b348919 300
MrBedfordVan 0:b9164b348919 301 /**
MrBedfordVan 0:b9164b348919 302 * Prints the given image to the display, if the display is not in use.
MrBedfordVan 0:b9164b348919 303 * Returns immediately, and executes the animation asynchronously.
MrBedfordVan 0:b9164b348919 304 *
MrBedfordVan 0:b9164b348919 305 * @param i The image to display.
MrBedfordVan 0:b9164b348919 306 *
MrBedfordVan 0:b9164b348919 307 * @param x The horizontal position on the screen to display the image. Defaults to 0.
MrBedfordVan 0:b9164b348919 308 *
MrBedfordVan 0:b9164b348919 309 * @param y The vertical position on the screen to display the image. Defaults to 0.
MrBedfordVan 0:b9164b348919 310 *
MrBedfordVan 0:b9164b348919 311 * @param alpha Treats the brightness level '0' as transparent. Defaults to 0.
MrBedfordVan 0:b9164b348919 312 *
MrBedfordVan 0:b9164b348919 313 * @param delay The time to delay between characters, in milliseconds. Defaults to 0.
MrBedfordVan 0:b9164b348919 314 *
MrBedfordVan 0:b9164b348919 315 * @code
MrBedfordVan 0:b9164b348919 316 * MicrobitImage i("1,1,1,1,1\n1,1,1,1,1\n");
MrBedfordVan 0:b9164b348919 317 * display.print(i,400);
MrBedfordVan 0:b9164b348919 318 * @endcode
MrBedfordVan 0:b9164b348919 319 */
MrBedfordVan 0:b9164b348919 320 int printAsync(MicroBitImage i, int x = 0, int y = 0, int alpha = 0, int delay = 0);
MrBedfordVan 0:b9164b348919 321
MrBedfordVan 0:b9164b348919 322 /**
MrBedfordVan 0:b9164b348919 323 * Prints the given character to the display.
MrBedfordVan 0:b9164b348919 324 *
MrBedfordVan 0:b9164b348919 325 * @param c The character to display.
MrBedfordVan 0:b9164b348919 326 *
MrBedfordVan 0:b9164b348919 327 * @param delay Optional parameter - the time for which to show the character. Zero displays the character forever,
MrBedfordVan 0:b9164b348919 328 * or until the Displays next use.
MrBedfordVan 0:b9164b348919 329 *
MrBedfordVan 0:b9164b348919 330 * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER.
MrBedfordVan 0:b9164b348919 331 *
MrBedfordVan 0:b9164b348919 332 * @code
MrBedfordVan 0:b9164b348919 333 * display.printAsync('p');
MrBedfordVan 0:b9164b348919 334 * display.printAsync('p',100);
MrBedfordVan 0:b9164b348919 335 * @endcode
MrBedfordVan 0:b9164b348919 336 */
MrBedfordVan 0:b9164b348919 337 int printChar(char c, int delay = 0);
MrBedfordVan 0:b9164b348919 338
MrBedfordVan 0:b9164b348919 339 /**
MrBedfordVan 0:b9164b348919 340 * Prints the given string to the display, one character at a time.
MrBedfordVan 0:b9164b348919 341 *
MrBedfordVan 0:b9164b348919 342 * Blocks the calling thread until all the text has been displayed.
MrBedfordVan 0:b9164b348919 343 *
MrBedfordVan 0:b9164b348919 344 * @param s The string to display.
MrBedfordVan 0:b9164b348919 345 *
MrBedfordVan 0:b9164b348919 346 * @param delay The time to delay between characters, in milliseconds. Defaults
MrBedfordVan 0:b9164b348919 347 * to: MICROBIT_DEFAULT_PRINT_SPEED.
MrBedfordVan 0:b9164b348919 348 *
MrBedfordVan 0:b9164b348919 349 * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER.
MrBedfordVan 0:b9164b348919 350 *
MrBedfordVan 0:b9164b348919 351 * @code
MrBedfordVan 0:b9164b348919 352 * display.print("abc123",400);
MrBedfordVan 0:b9164b348919 353 * @endcode
MrBedfordVan 0:b9164b348919 354 */
MrBedfordVan 0:b9164b348919 355 int print(ManagedString s, int delay = MICROBIT_DEFAULT_PRINT_SPEED);
MrBedfordVan 0:b9164b348919 356
MrBedfordVan 0:b9164b348919 357 /**
MrBedfordVan 0:b9164b348919 358 * Prints the given image to the display.
MrBedfordVan 0:b9164b348919 359 * Blocks the calling thread until all the image has been displayed.
MrBedfordVan 0:b9164b348919 360 *
MrBedfordVan 0:b9164b348919 361 * @param i The image to display.
MrBedfordVan 0:b9164b348919 362 *
MrBedfordVan 0:b9164b348919 363 * @param x The horizontal position on the screen to display the image. Defaults to 0.
MrBedfordVan 0:b9164b348919 364 *
MrBedfordVan 0:b9164b348919 365 * @param y The vertical position on the screen to display the image. Defaults to 0.
MrBedfordVan 0:b9164b348919 366 *
MrBedfordVan 0:b9164b348919 367 * @param alpha Treats the brightness level '0' as transparent. Defaults to 0.
MrBedfordVan 0:b9164b348919 368 *
MrBedfordVan 0:b9164b348919 369 * @param delay The time to display the image for, or zero to show the image forever. Defaults to 0.
MrBedfordVan 0:b9164b348919 370 *
MrBedfordVan 0:b9164b348919 371 * @return MICROBIT_OK, MICROBIT_BUSY if the display is already in use, or MICROBIT_INVALID_PARAMETER.
MrBedfordVan 0:b9164b348919 372 *
MrBedfordVan 0:b9164b348919 373 * @code
MrBedfordVan 0:b9164b348919 374 * MicrobitImage i("1,1,1,1,1\n1,1,1,1,1\n");
MrBedfordVan 0:b9164b348919 375 * display.print(i,400);
MrBedfordVan 0:b9164b348919 376 * @endcode
MrBedfordVan 0:b9164b348919 377 */
MrBedfordVan 0:b9164b348919 378 int print(MicroBitImage i, int x = 0, int y = 0, int alpha = 0, int delay = 0);
MrBedfordVan 0:b9164b348919 379
MrBedfordVan 0:b9164b348919 380 /**
MrBedfordVan 0:b9164b348919 381 * Scrolls the given string to the display, from right to left.
MrBedfordVan 0:b9164b348919 382 * Returns immediately, and executes the animation asynchronously.
MrBedfordVan 0:b9164b348919 383 *
MrBedfordVan 0:b9164b348919 384 * @param s The string to display.
MrBedfordVan 0:b9164b348919 385 *
MrBedfordVan 0:b9164b348919 386 * @param delay The time to delay between characters, in milliseconds. Defaults
MrBedfordVan 0:b9164b348919 387 * to: MICROBIT_DEFAULT_SCROLL_SPEED.
MrBedfordVan 0:b9164b348919 388 *
MrBedfordVan 0:b9164b348919 389 * @return MICROBIT_OK, MICROBIT_BUSY if the display is already in use, or MICROBIT_INVALID_PARAMETER.
MrBedfordVan 0:b9164b348919 390 *
MrBedfordVan 0:b9164b348919 391 * @code
MrBedfordVan 0:b9164b348919 392 * display.scrollAsync("abc123",100);
MrBedfordVan 0:b9164b348919 393 * @endcode
MrBedfordVan 0:b9164b348919 394 */
MrBedfordVan 0:b9164b348919 395 int scrollAsync(ManagedString s, int delay = MICROBIT_DEFAULT_SCROLL_SPEED);
MrBedfordVan 0:b9164b348919 396
MrBedfordVan 0:b9164b348919 397 /**
MrBedfordVan 0:b9164b348919 398 * Scrolls the given image across the display, from right to left.
MrBedfordVan 0:b9164b348919 399 * Returns immediately, and executes the animation asynchronously.
MrBedfordVan 0:b9164b348919 400 *
MrBedfordVan 0:b9164b348919 401 * @param image The image to display.
MrBedfordVan 0:b9164b348919 402 *
MrBedfordVan 0:b9164b348919 403 * @param delay The time between updates, in milliseconds. Defaults
MrBedfordVan 0:b9164b348919 404 * to: MICROBIT_DEFAULT_SCROLL_SPEED.
MrBedfordVan 0:b9164b348919 405 *
MrBedfordVan 0:b9164b348919 406 * @param stride The number of pixels to shift by in each update. Defaults to MICROBIT_DEFAULT_SCROLL_STRIDE.
MrBedfordVan 0:b9164b348919 407 *
MrBedfordVan 0:b9164b348919 408 * @return MICROBIT_OK, MICROBIT_BUSY if the display is already in use, or MICROBIT_INVALID_PARAMETER.
MrBedfordVan 0:b9164b348919 409 *
MrBedfordVan 0:b9164b348919 410 * @code
MrBedfordVan 0:b9164b348919 411 * MicrobitImage i("1,1,1,1,1\n1,1,1,1,1\n");
MrBedfordVan 0:b9164b348919 412 * display.scrollAsync(i,100,1);
MrBedfordVan 0:b9164b348919 413 * @endcode
MrBedfordVan 0:b9164b348919 414 */
MrBedfordVan 0:b9164b348919 415 int scrollAsync(MicroBitImage image, int delay = MICROBIT_DEFAULT_SCROLL_SPEED, int stride = MICROBIT_DEFAULT_SCROLL_STRIDE);
MrBedfordVan 0:b9164b348919 416
MrBedfordVan 0:b9164b348919 417 /**
MrBedfordVan 0:b9164b348919 418 * Scrolls the given string across the display, from right to left.
MrBedfordVan 0:b9164b348919 419 * Blocks the calling thread until all text has been displayed.
MrBedfordVan 0:b9164b348919 420 *
MrBedfordVan 0:b9164b348919 421 * @param s The string to display.
MrBedfordVan 0:b9164b348919 422 *
MrBedfordVan 0:b9164b348919 423 * @param delay The time to delay between characters, in milliseconds. Defaults
MrBedfordVan 0:b9164b348919 424 * to: MICROBIT_DEFAULT_SCROLL_SPEED.
MrBedfordVan 0:b9164b348919 425 *
MrBedfordVan 0:b9164b348919 426 * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER.
MrBedfordVan 0:b9164b348919 427 *
MrBedfordVan 0:b9164b348919 428 * @code
MrBedfordVan 0:b9164b348919 429 * display.scroll("abc123",100);
MrBedfordVan 0:b9164b348919 430 * @endcode
MrBedfordVan 0:b9164b348919 431 */
MrBedfordVan 0:b9164b348919 432 int scroll(ManagedString s, int delay = MICROBIT_DEFAULT_SCROLL_SPEED);
MrBedfordVan 0:b9164b348919 433
MrBedfordVan 0:b9164b348919 434 /**
MrBedfordVan 0:b9164b348919 435 * Scrolls the given image across the display, from right to left.
MrBedfordVan 0:b9164b348919 436 * Blocks the calling thread until all the text has been displayed.
MrBedfordVan 0:b9164b348919 437 *
MrBedfordVan 0:b9164b348919 438 * @param image The image to display.
MrBedfordVan 0:b9164b348919 439 *
MrBedfordVan 0:b9164b348919 440 * @param delay The time between updates, in milliseconds. Defaults
MrBedfordVan 0:b9164b348919 441 * to: MICROBIT_DEFAULT_SCROLL_SPEED.
MrBedfordVan 0:b9164b348919 442 *
MrBedfordVan 0:b9164b348919 443 * @param stride The number of pixels to shift by in each update. Defaults to MICROBIT_DEFAULT_SCROLL_STRIDE.
MrBedfordVan 0:b9164b348919 444 *
MrBedfordVan 0:b9164b348919 445 * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER.
MrBedfordVan 0:b9164b348919 446 *
MrBedfordVan 0:b9164b348919 447 * @code
MrBedfordVan 0:b9164b348919 448 * MicrobitImage i("1,1,1,1,1\n1,1,1,1,1\n");
MrBedfordVan 0:b9164b348919 449 * display.scroll(i,100,1);
MrBedfordVan 0:b9164b348919 450 * @endcode
MrBedfordVan 0:b9164b348919 451 */
MrBedfordVan 0:b9164b348919 452 int scroll(MicroBitImage image, int delay = MICROBIT_DEFAULT_SCROLL_SPEED, int stride = MICROBIT_DEFAULT_SCROLL_STRIDE);
MrBedfordVan 0:b9164b348919 453
MrBedfordVan 0:b9164b348919 454 /**
MrBedfordVan 0:b9164b348919 455 * "Animates" the current image across the display with a given stride, finishing on the last frame of the animation.
MrBedfordVan 0:b9164b348919 456 * Returns immediately.
MrBedfordVan 0:b9164b348919 457 *
MrBedfordVan 0:b9164b348919 458 * @param image The image to display.
MrBedfordVan 0:b9164b348919 459 *
MrBedfordVan 0:b9164b348919 460 * @param delay The time to delay between each update of the display, in milliseconds.
MrBedfordVan 0:b9164b348919 461 *
MrBedfordVan 0:b9164b348919 462 * @param stride The number of pixels to shift by in each update.
MrBedfordVan 0:b9164b348919 463 *
MrBedfordVan 0:b9164b348919 464 * @param startingPosition the starting position on the display for the animation
MrBedfordVan 0:b9164b348919 465 * to begin at. Defaults to MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS.
MrBedfordVan 0:b9164b348919 466 *
MrBedfordVan 0:b9164b348919 467 * @param autoClear defines whether or not the display is automatically cleared once the animation is complete. By default, the display is cleared. Set this parameter to zero to disable the autoClear operation.
MrBedfordVan 0:b9164b348919 468 *
MrBedfordVan 0:b9164b348919 469 * @return MICROBIT_OK, MICROBIT_BUSY if the screen is in use, or MICROBIT_INVALID_PARAMETER.
MrBedfordVan 0:b9164b348919 470 *
MrBedfordVan 0:b9164b348919 471 * @code
MrBedfordVan 0:b9164b348919 472 * const int heart_w = 10;
MrBedfordVan 0:b9164b348919 473 * const int heart_h = 5;
MrBedfordVan 0:b9164b348919 474 * const uint8_t heart[] = { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, };
MrBedfordVan 0:b9164b348919 475 *
MrBedfordVan 0:b9164b348919 476 * MicroBitImage i(heart_w,heart_h,heart);
MrBedfordVan 0:b9164b348919 477 * display.animateAsync(i,100,5);
MrBedfordVan 0:b9164b348919 478 * @endcode
MrBedfordVan 0:b9164b348919 479 */
MrBedfordVan 0:b9164b348919 480 int animateAsync(MicroBitImage image, int delay, int stride, int startingPosition = MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS, int autoClear = MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR);
MrBedfordVan 0:b9164b348919 481
MrBedfordVan 0:b9164b348919 482 /**
MrBedfordVan 0:b9164b348919 483 * "Animates" the current image across the display with a given stride, finishing on the last frame of the animation.
MrBedfordVan 0:b9164b348919 484 * Blocks the calling thread until the animation is complete.
MrBedfordVan 0:b9164b348919 485 *
MrBedfordVan 0:b9164b348919 486 *
MrBedfordVan 0:b9164b348919 487 * @param delay The time to delay between each update of the display, in milliseconds.
MrBedfordVan 0:b9164b348919 488 *
MrBedfordVan 0:b9164b348919 489 * @param stride The number of pixels to shift by in each update.
MrBedfordVan 0:b9164b348919 490 *
MrBedfordVan 0:b9164b348919 491 * @param startingPosition the starting position on the display for the animation
MrBedfordVan 0:b9164b348919 492 * to begin at. Defaults to MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS.
MrBedfordVan 0:b9164b348919 493 *
MrBedfordVan 0:b9164b348919 494 * @param autoClear defines whether or not the display is automatically cleared once the animation is complete. By default, the display is cleared. Set this parameter to zero to disable the autoClear operation.
MrBedfordVan 0:b9164b348919 495 *
MrBedfordVan 0:b9164b348919 496 * @return MICROBIT_OK, MICROBIT_CANCELLED or MICROBIT_INVALID_PARAMETER.
MrBedfordVan 0:b9164b348919 497 *
MrBedfordVan 0:b9164b348919 498 * @code
MrBedfordVan 0:b9164b348919 499 * const int heart_w = 10;
MrBedfordVan 0:b9164b348919 500 * const int heart_h = 5;
MrBedfordVan 0:b9164b348919 501 * const uint8_t heart[] = { 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, };
MrBedfordVan 0:b9164b348919 502 *
MrBedfordVan 0:b9164b348919 503 * MicroBitImage i(heart_w,heart_h,heart);
MrBedfordVan 0:b9164b348919 504 * display.animate(i,100,5);
MrBedfordVan 0:b9164b348919 505 * @endcode
MrBedfordVan 0:b9164b348919 506 */
MrBedfordVan 0:b9164b348919 507 int animate(MicroBitImage image, int delay, int stride, int startingPosition = MICROBIT_DISPLAY_ANIMATE_DEFAULT_POS, int autoClear = MICROBIT_DISPLAY_DEFAULT_AUTOCLEAR);
MrBedfordVan 0:b9164b348919 508
MrBedfordVan 0:b9164b348919 509 /**
MrBedfordVan 0:b9164b348919 510 * Configures the brightness of the display.
MrBedfordVan 0:b9164b348919 511 *
MrBedfordVan 0:b9164b348919 512 * @param b The brightness to set the brightness to, in the range 0 - 255.
MrBedfordVan 0:b9164b348919 513 *
MrBedfordVan 0:b9164b348919 514 * @return MICROBIT_OK, or MICROBIT_INVALID_PARAMETER
MrBedfordVan 0:b9164b348919 515 *
MrBedfordVan 0:b9164b348919 516 * @code
MrBedfordVan 0:b9164b348919 517 * display.setBrightness(255); //max brightness
MrBedfordVan 0:b9164b348919 518 * @endcode
MrBedfordVan 0:b9164b348919 519 */
MrBedfordVan 0:b9164b348919 520 int setBrightness(int b);
MrBedfordVan 0:b9164b348919 521
MrBedfordVan 0:b9164b348919 522 /**
MrBedfordVan 0:b9164b348919 523 * Configures the mode of the display.
MrBedfordVan 0:b9164b348919 524 *
MrBedfordVan 0:b9164b348919 525 * @param mode The mode to swap the display into. One of: DISPLAY_MODE_GREYSCALE,
MrBedfordVan 0:b9164b348919 526 * DISPLAY_MODE_BLACK_AND_WHITE, DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE
MrBedfordVan 0:b9164b348919 527 *
MrBedfordVan 0:b9164b348919 528 * @code
MrBedfordVan 0:b9164b348919 529 * display.setDisplayMode(DISPLAY_MODE_GREYSCALE); //per pixel brightness
MrBedfordVan 0:b9164b348919 530 * @endcode
MrBedfordVan 0:b9164b348919 531 */
MrBedfordVan 0:b9164b348919 532 void setDisplayMode(DisplayMode mode);
MrBedfordVan 0:b9164b348919 533
MrBedfordVan 0:b9164b348919 534 /**
MrBedfordVan 0:b9164b348919 535 * Retrieves the mode of the display.
MrBedfordVan 0:b9164b348919 536 *
MrBedfordVan 0:b9164b348919 537 * @return the current mode of the display
MrBedfordVan 0:b9164b348919 538 */
MrBedfordVan 0:b9164b348919 539 int getDisplayMode();
MrBedfordVan 0:b9164b348919 540
MrBedfordVan 0:b9164b348919 541 /**
MrBedfordVan 0:b9164b348919 542 * Fetches the current brightness of this display.
MrBedfordVan 0:b9164b348919 543 *
MrBedfordVan 0:b9164b348919 544 * @return the brightness of this display, in the range 0..255.
MrBedfordVan 0:b9164b348919 545 *
MrBedfordVan 0:b9164b348919 546 * @code
MrBedfordVan 0:b9164b348919 547 * display.getBrightness(); //the current brightness
MrBedfordVan 0:b9164b348919 548 * @endcode
MrBedfordVan 0:b9164b348919 549 */
MrBedfordVan 0:b9164b348919 550 int getBrightness();
MrBedfordVan 0:b9164b348919 551
MrBedfordVan 0:b9164b348919 552 /**
MrBedfordVan 0:b9164b348919 553 * Rotates the display to the given position.
MrBedfordVan 0:b9164b348919 554 *
MrBedfordVan 0:b9164b348919 555 * Axis aligned values only.
MrBedfordVan 0:b9164b348919 556 *
MrBedfordVan 0:b9164b348919 557 * @code
MrBedfordVan 0:b9164b348919 558 * display.rotateTo(MICROBIT_DISPLAY_ROTATION_180); //rotates 180 degrees from original orientation
MrBedfordVan 0:b9164b348919 559 * @endcode
MrBedfordVan 0:b9164b348919 560 */
MrBedfordVan 0:b9164b348919 561 void rotateTo(DisplayRotation position);
MrBedfordVan 0:b9164b348919 562
MrBedfordVan 0:b9164b348919 563 /**
MrBedfordVan 0:b9164b348919 564 * Enables the display, should only be called if the display is disabled.
MrBedfordVan 0:b9164b348919 565 *
MrBedfordVan 0:b9164b348919 566 * @code
MrBedfordVan 0:b9164b348919 567 * display.enable(); //Enables the display mechanics
MrBedfordVan 0:b9164b348919 568 * @endcode
MrBedfordVan 0:b9164b348919 569 *
MrBedfordVan 0:b9164b348919 570 * @note Only enables the display if the display is currently disabled.
MrBedfordVan 0:b9164b348919 571 */
MrBedfordVan 0:b9164b348919 572 void enable();
MrBedfordVan 0:b9164b348919 573
MrBedfordVan 0:b9164b348919 574 /**
MrBedfordVan 0:b9164b348919 575 * Disables the display, which releases control of the GPIO pins used by the display,
MrBedfordVan 0:b9164b348919 576 * which are exposed on the edge connector.
MrBedfordVan 0:b9164b348919 577 *
MrBedfordVan 0:b9164b348919 578 * @code
MrBedfordVan 0:b9164b348919 579 * display.disable(); //disables the display
MrBedfordVan 0:b9164b348919 580 * @endcode
MrBedfordVan 0:b9164b348919 581 *
MrBedfordVan 0:b9164b348919 582 * @note Only disables the display if the display is currently enabled.
MrBedfordVan 0:b9164b348919 583 */
MrBedfordVan 0:b9164b348919 584 void disable();
MrBedfordVan 0:b9164b348919 585
MrBedfordVan 0:b9164b348919 586 /**
MrBedfordVan 0:b9164b348919 587 * Clears the display of any remaining pixels.
MrBedfordVan 0:b9164b348919 588 *
MrBedfordVan 0:b9164b348919 589 * `display.image.clear()` can also be used!
MrBedfordVan 0:b9164b348919 590 *
MrBedfordVan 0:b9164b348919 591 * @code
MrBedfordVan 0:b9164b348919 592 * display.clear(); //clears the display
MrBedfordVan 0:b9164b348919 593 * @endcode
MrBedfordVan 0:b9164b348919 594 */
MrBedfordVan 0:b9164b348919 595 void clear();
MrBedfordVan 0:b9164b348919 596
MrBedfordVan 0:b9164b348919 597 /**
MrBedfordVan 0:b9164b348919 598 * Updates the font that will be used for display operations.
MrBedfordVan 0:b9164b348919 599 *
MrBedfordVan 0:b9164b348919 600 * @param font the new font that will be used to render characters.
MrBedfordVan 0:b9164b348919 601 *
MrBedfordVan 0:b9164b348919 602 * @note DEPRECATED! Please use MicroBitFont::setSystemFont() instead.
MrBedfordVan 0:b9164b348919 603 */
MrBedfordVan 0:b9164b348919 604 void setFont(MicroBitFont font);
MrBedfordVan 0:b9164b348919 605
MrBedfordVan 0:b9164b348919 606 /**
MrBedfordVan 0:b9164b348919 607 * Retrieves the font object used for rendering characters on the display.
MrBedfordVan 0:b9164b348919 608 *
MrBedfordVan 0:b9164b348919 609 * @note DEPRECATED! Please use MicroBitFont::getSystemFont() instead.
MrBedfordVan 0:b9164b348919 610 */
MrBedfordVan 0:b9164b348919 611 MicroBitFont getFont();
MrBedfordVan 0:b9164b348919 612
MrBedfordVan 0:b9164b348919 613 /**
MrBedfordVan 0:b9164b348919 614 * Captures the bitmap currently being rendered on the display.
MrBedfordVan 0:b9164b348919 615 *
MrBedfordVan 0:b9164b348919 616 * @return a MicroBitImage containing the captured data.
MrBedfordVan 0:b9164b348919 617 */
MrBedfordVan 0:b9164b348919 618 MicroBitImage screenShot();
MrBedfordVan 0:b9164b348919 619
MrBedfordVan 0:b9164b348919 620 /**
MrBedfordVan 0:b9164b348919 621 * Gives a representative figure of the light level in the current environment
MrBedfordVan 0:b9164b348919 622 * where are micro:bit is situated.
MrBedfordVan 0:b9164b348919 623 *
MrBedfordVan 0:b9164b348919 624 * Internally, it constructs an instance of a MicroBitLightSensor if not already configured
MrBedfordVan 0:b9164b348919 625 * and sets the display mode to DISPLAY_MODE_BLACK_AND_WHITE_LIGHT_SENSE.
MrBedfordVan 0:b9164b348919 626 *
MrBedfordVan 0:b9164b348919 627 * This also changes the tickPeriod to MICROBIT_LIGHT_SENSOR_TICK_SPEED so
MrBedfordVan 0:b9164b348919 628 * that the display does not suffer from artifacts.
MrBedfordVan 0:b9164b348919 629 *
MrBedfordVan 0:b9164b348919 630 * @return an indicative light level in the range 0 - 255.
MrBedfordVan 0:b9164b348919 631 *
MrBedfordVan 0:b9164b348919 632 * @note this will return 0 on the first call to this method, a light reading
MrBedfordVan 0:b9164b348919 633 * will be available after the display has activated the light sensor for the
MrBedfordVan 0:b9164b348919 634 * first time.
MrBedfordVan 0:b9164b348919 635 */
MrBedfordVan 0:b9164b348919 636 int readLightLevel();
MrBedfordVan 0:b9164b348919 637
MrBedfordVan 0:b9164b348919 638 /**
MrBedfordVan 0:b9164b348919 639 * Destructor for MicroBitDisplay, where we deregister this instance from the array of system components.
MrBedfordVan 0:b9164b348919 640 */
MrBedfordVan 0:b9164b348919 641 ~MicroBitDisplay();
MrBedfordVan 0:b9164b348919 642 };
MrBedfordVan 0:b9164b348919 643
MrBedfordVan 0:b9164b348919 644 #endif