Robotics Interest Club
/
Ticker_program
a 3_mins_countdown program used ticker
Fork of Countdown by
main.cpp@1:45d4a6581987, 2015-11-06 (annotated)
- Committer:
- jwb
- Date:
- Fri Nov 06 12:10:01 2015 +0000
- Revision:
- 1:45d4a6581987
- Parent:
- 0:bd5143ec272b
a simple program to use ticker
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ms523 | 0:bd5143ec272b | 1 | #include "mbed.h" |
jwb | 1:45d4a6581987 | 2 | #include "C12832.h" |
ms523 | 0:bd5143ec272b | 3 | |
jwb | 1:45d4a6581987 | 4 | BusOut leds(LED1,LED2,LED3,LED4); // this is the bus out of leds, so all the leds can be control in one time |
jwb | 1:45d4a6581987 | 5 | C12832 lcd(p5, p7, p6, p8, p11); |
jwb | 1:45d4a6581987 | 6 | Ticker Timer_100ms; // a ticker is similar to a interrupt |
jwb | 1:45d4a6581987 | 7 | int count=180; |
ms523 | 0:bd5143ec272b | 8 | |
jwb | 1:45d4a6581987 | 9 | void Countdown(void) // this is what is inside the ticker will do |
jwb | 1:45d4a6581987 | 10 | { |
jwb | 1:45d4a6581987 | 11 | count--; |
ms523 | 0:bd5143ec272b | 12 | } |
ms523 | 0:bd5143ec272b | 13 | |
ms523 | 0:bd5143ec272b | 14 | int main() { |
ms523 | 0:bd5143ec272b | 15 | |
jwb | 1:45d4a6581987 | 16 | Timer_100ms.attach(&Countdown, 1); //Call Countdown every 1 second *** format: ticker_name.attach(&void_name,time) |
jwb | 1:45d4a6581987 | 17 | lcd.cls(); //clear screen |
jwb | 1:45d4a6581987 | 18 | while(1) |
jwb | 1:45d4a6581987 | 19 | { |
jwb | 1:45d4a6581987 | 20 | lcd.cls(); |
jwb | 1:45d4a6581987 | 21 | lcd.locate(0,0); |
jwb | 1:45d4a6581987 | 22 | lcd.printf("%d",count); //countdown number will display on LCD |
jwb | 1:45d4a6581987 | 23 | wait(.1); |
jwb | 1:45d4a6581987 | 24 | if(count==0) |
jwb | 1:45d4a6581987 | 25 | { |
jwb | 1:45d4a6581987 | 26 | Timer_100ms.detach(); // this will disable the ticker |
jwb | 1:45d4a6581987 | 27 | count=180; // reset the count |
jwb | 1:45d4a6581987 | 28 | leds=0xFFFF; //leds all will light up with the hex number of 0xFFFF |
jwb | 1:45d4a6581987 | 29 | } |
ms523 | 0:bd5143ec272b | 30 | } |
ms523 | 0:bd5143ec272b | 31 | } |