Just a Simple Clock, before uplaoding the code, make sure to update the time
Revision 0:1c173fd39b43, committed 2017-02-25
- Comitter:
- neoxharsh
- Date:
- Sat Feb 25 11:16:14 2017 +0000
- Commit message:
- Microbit Clock;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
microbit.lib | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Feb 25 11:16:14 2017 +0000 @@ -0,0 +1,58 @@ +#include "MicroBit.h" + +const int DATA_ID = MICROBIT_ID_NOTIFY+1; // last defined eventId is MICROBIT_ID_NOTIFY==1023 in MicroBitComponent.h +const int NEW_DATA = 1; + +MicroBit uBit; + +int seconds = 0, minutes= 43, hours=16,currentHour=0; +ManagedString AMPM; + +void ticker() +{ + while(1) + { + seconds++; + uBit.sleep(1000); + if (seconds==60) + { + seconds = 0; + minutes++; + } + if (minutes==60) + { + minutes=0; + hours++; + } + if (hours==24) + { + hours = 0; + } + if (hours>12) + { + currentHour = hours - 12; + AMPM = "PM"; + } + else + { + AMPM = "AM"; + } + MicroBitEvent(DATA_ID,NEW_DATA); + } +} + +void timeDisplay(MicroBitEvent evt) +{ +uBit.display.setBrightness(250); + uBit.display.scrollAsync(ManagedString(currentHour)+":"+ManagedString(minutes)+ManagedString(AMPM),80); + } + +int main() +{ + uBit.init(); + uBit.messageBus.listen(DATA_ID,NEW_DATA,timeDisplay); + + create_fiber(ticker); + release_fiber(); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/microbit.lib Sat Feb 25 11:16:14 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/Lancaster-University/code/microbit/#4b89e7e3494f