Takes a user input (value between 0 and 99) and starts a countdown from that value. The countdown is printed to the serial port and to the 7 segment displays on the RenBed.

Dependencies:   SevenSegmentDisplay USBDevice mbed

Committer:
rantistic
Date:
Wed Feb 25 10:21:59 2015 +0000
Revision:
1:252cc1fa8e32
Parent:
0:a2be69659f88
updated version so works with new libraries

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rantistic 0:a2be69659f88 1 #include "mbed.h"
rantistic 0:a2be69659f88 2 #include "USBSerial.h"
rantistic 0:a2be69659f88 3 #include "SevenSegmentDisplay.h"
rantistic 0:a2be69659f88 4
rantistic 0:a2be69659f88 5 //Virtual serial port over USB
rantistic 0:a2be69659f88 6 USBSerial serial;
rantistic 0:a2be69659f88 7
rantistic 1:252cc1fa8e32 8 int countdown;
rantistic 1:252cc1fa8e32 9 int startno = 6;
rantistic 1:252cc1fa8e32 10 int userinputno; // do not initialise scanf values as this creates problems
rantistic 0:a2be69659f88 11
rantistic 0:a2be69659f88 12 SevenSegmentDisplay segmentled( FADE );
rantistic 0:a2be69659f88 13 Ticker timeout;
rantistic 0:a2be69659f88 14
rantistic 0:a2be69659f88 15 void attimeout();
rantistic 0:a2be69659f88 16
rantistic 0:a2be69659f88 17 int main(void)
rantistic 0:a2be69659f88 18 {
rantistic 0:a2be69659f88 19
rantistic 0:a2be69659f88 20
rantistic 0:a2be69659f88 21 while(1)
rantistic 0:a2be69659f88 22 {
rantistic 0:a2be69659f88 23 wait(1);
rantistic 0:a2be69659f88 24 for(countdown=startno; countdown>0; countdown--)
rantistic 0:a2be69659f88 25 {
rantistic 0:a2be69659f88 26 segmentled.DisplayInt(countdown);
rantistic 1:252cc1fa8e32 27 serial.printf("%d\n\r", countdown);
rantistic 0:a2be69659f88 28 wait(1);
rantistic 0:a2be69659f88 29 }
rantistic 0:a2be69659f88 30
rantistic 0:a2be69659f88 31 countdown = 0;
rantistic 0:a2be69659f88 32 segmentled.DisplayInt(countdown);
rantistic 1:252cc1fa8e32 33 serial.printf("%d\n\r", countdown);
rantistic 0:a2be69659f88 34 serial.printf("Hi User! Please enter a number between 2 and 99\n\r");
rantistic 1:252cc1fa8e32 35 serial.scanf("%d", &userinputno);
rantistic 0:a2be69659f88 36 segmentled.DisplayInt(userinputno);
rantistic 1:252cc1fa8e32 37 serial.printf("The countdown will now start from %d ... \n\r", userinputno);
rantistic 0:a2be69659f88 38
rantistic 1:252cc1fa8e32 39 wait(1);
rantistic 0:a2be69659f88 40
rantistic 0:a2be69659f88 41 startno = userinputno;
rantistic 0:a2be69659f88 42 }
rantistic 0:a2be69659f88 43 }