Just a Simple Clock, before uplaoding the code, make sure to update the time

Dependencies:   microbit

Committer:
neoxharsh
Date:
Sat Feb 25 11:16:14 2017 +0000
Revision:
0:1c173fd39b43
Microbit Clock;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
neoxharsh 0:1c173fd39b43 1 #include "MicroBit.h"
neoxharsh 0:1c173fd39b43 2
neoxharsh 0:1c173fd39b43 3 const int DATA_ID = MICROBIT_ID_NOTIFY+1; // last defined eventId is MICROBIT_ID_NOTIFY==1023 in MicroBitComponent.h
neoxharsh 0:1c173fd39b43 4 const int NEW_DATA = 1;
neoxharsh 0:1c173fd39b43 5
neoxharsh 0:1c173fd39b43 6 MicroBit uBit;
neoxharsh 0:1c173fd39b43 7
neoxharsh 0:1c173fd39b43 8 int seconds = 0, minutes= 43, hours=16,currentHour=0;
neoxharsh 0:1c173fd39b43 9 ManagedString AMPM;
neoxharsh 0:1c173fd39b43 10
neoxharsh 0:1c173fd39b43 11 void ticker()
neoxharsh 0:1c173fd39b43 12 {
neoxharsh 0:1c173fd39b43 13 while(1)
neoxharsh 0:1c173fd39b43 14 {
neoxharsh 0:1c173fd39b43 15 seconds++;
neoxharsh 0:1c173fd39b43 16 uBit.sleep(1000);
neoxharsh 0:1c173fd39b43 17 if (seconds==60)
neoxharsh 0:1c173fd39b43 18 {
neoxharsh 0:1c173fd39b43 19 seconds = 0;
neoxharsh 0:1c173fd39b43 20 minutes++;
neoxharsh 0:1c173fd39b43 21 }
neoxharsh 0:1c173fd39b43 22 if (minutes==60)
neoxharsh 0:1c173fd39b43 23 {
neoxharsh 0:1c173fd39b43 24 minutes=0;
neoxharsh 0:1c173fd39b43 25 hours++;
neoxharsh 0:1c173fd39b43 26 }
neoxharsh 0:1c173fd39b43 27 if (hours==24)
neoxharsh 0:1c173fd39b43 28 {
neoxharsh 0:1c173fd39b43 29 hours = 0;
neoxharsh 0:1c173fd39b43 30 }
neoxharsh 0:1c173fd39b43 31 if (hours>12)
neoxharsh 0:1c173fd39b43 32 {
neoxharsh 0:1c173fd39b43 33 currentHour = hours - 12;
neoxharsh 0:1c173fd39b43 34 AMPM = "PM";
neoxharsh 0:1c173fd39b43 35 }
neoxharsh 0:1c173fd39b43 36 else
neoxharsh 0:1c173fd39b43 37 {
neoxharsh 0:1c173fd39b43 38 AMPM = "AM";
neoxharsh 0:1c173fd39b43 39 }
neoxharsh 0:1c173fd39b43 40 MicroBitEvent(DATA_ID,NEW_DATA);
neoxharsh 0:1c173fd39b43 41 }
neoxharsh 0:1c173fd39b43 42 }
neoxharsh 0:1c173fd39b43 43
neoxharsh 0:1c173fd39b43 44 void timeDisplay(MicroBitEvent evt)
neoxharsh 0:1c173fd39b43 45 {
neoxharsh 0:1c173fd39b43 46 uBit.display.setBrightness(250);
neoxharsh 0:1c173fd39b43 47 uBit.display.scrollAsync(ManagedString(currentHour)+":"+ManagedString(minutes)+ManagedString(AMPM),80);
neoxharsh 0:1c173fd39b43 48 }
neoxharsh 0:1c173fd39b43 49
neoxharsh 0:1c173fd39b43 50 int main()
neoxharsh 0:1c173fd39b43 51 {
neoxharsh 0:1c173fd39b43 52 uBit.init();
neoxharsh 0:1c173fd39b43 53 uBit.messageBus.listen(DATA_ID,NEW_DATA,timeDisplay);
neoxharsh 0:1c173fd39b43 54
neoxharsh 0:1c173fd39b43 55 create_fiber(ticker);
neoxharsh 0:1c173fd39b43 56 release_fiber();
neoxharsh 0:1c173fd39b43 57 }
neoxharsh 0:1c173fd39b43 58