Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of MicroBitDALImageRewrite by
MicroBitLED.cpp@0:47d8ba08580f, 2015-04-12 (annotated)
- Committer:
- finneyj
- Date:
- Sun Apr 12 17:38:56 2015 +0000
- Revision:
- 0:47d8ba08580f
First draft implementation of core functionality. Includes:; ; - OO model of microBit device.; - Flexible geometry LD matirx driver.; - Lazy, instatiation free I/O; ; Please note this code is largely untested.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| finneyj | 0:47d8ba08580f | 1 | |
| finneyj | 0:47d8ba08580f | 2 | #include "inc/MicroBitLED.h" | 
| finneyj | 0:47d8ba08580f | 3 | |
| finneyj | 0:47d8ba08580f | 4 | |
| finneyj | 0:47d8ba08580f | 5 | /** | 
| finneyj | 0:47d8ba08580f | 6 | * Constructor. | 
| finneyj | 0:47d8ba08580f | 7 | * Create an LED representation with the given ID. | 
| finneyj | 0:47d8ba08580f | 8 | * @param id the ID of the new LED object. | 
| finneyj | 0:47d8ba08580f | 9 | */ | 
| finneyj | 0:47d8ba08580f | 10 | MicroBitLED::MicroBitLED(int id, PinName name) : | 
| finneyj | 0:47d8ba08580f | 11 | pin(name) | 
| finneyj | 0:47d8ba08580f | 12 | |
| finneyj | 0:47d8ba08580f | 13 | { | 
| finneyj | 0:47d8ba08580f | 14 | this->id = id; | 
| finneyj | 0:47d8ba08580f | 15 | } | 
| finneyj | 0:47d8ba08580f | 16 | |
| finneyj | 0:47d8ba08580f | 17 | |
| finneyj | 0:47d8ba08580f | 18 | /** | 
| finneyj | 0:47d8ba08580f | 19 | * Sets this LED to the brightness specified. | 
| finneyj | 0:47d8ba08580f | 20 | * @param b The brightness to set the LED, in the range 0..255. | 
| finneyj | 0:47d8ba08580f | 21 | */ | 
| finneyj | 0:47d8ba08580f | 22 | void MicroBitLED::setBrightness(int b) | 
| finneyj | 0:47d8ba08580f | 23 | { | 
| finneyj | 0:47d8ba08580f | 24 | pin.write(b > 0); | 
| finneyj | 0:47d8ba08580f | 25 | } | 
| finneyj | 0:47d8ba08580f | 26 | |
| finneyj | 0:47d8ba08580f | 27 | /** | 
| finneyj | 0:47d8ba08580f | 28 | * Tests the brightness of this LED. | 
| finneyj | 0:47d8ba08580f | 29 | * @return the brightness of this LED, in the range 0..255. | 
| finneyj | 0:47d8ba08580f | 30 | */ | 
| finneyj | 0:47d8ba08580f | 31 | int MicroBitLED::getBrightness() | 
| finneyj | 0:47d8ba08580f | 32 | { | 
| finneyj | 0:47d8ba08580f | 33 | return pin.read() == 0 ? 0 : 255; | 
| finneyj | 0:47d8ba08580f | 34 | } | 
| finneyj | 0:47d8ba08580f | 35 | 
