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

main.cpp

Committer:
rantistic
Date:
2014-10-24
Revision:
0:a2be69659f88
Child:
1:252cc1fa8e32

File content as of revision 0:a2be69659f88:

#include "mbed.h"
#include "USBSerial.h"
#include "SevenSegmentDisplay.h"
 
//Virtual serial port over USB
USBSerial serial;

uint8_t countdown;
uint8_t startno = 6;
uint8_t userinputno; // do not initialise scanf values as this creates problems

SevenSegmentDisplay segmentled( FADE );
Ticker timeout;

void attimeout();

int main(void)
{

            
    while(1)
    {
       wait(1);
       for(countdown=startno; countdown>0; countdown--)
         {
             segmentled.DisplayInt(countdown);
             serial.printf("%u\n\r", countdown);
             wait(1);
         }
        
        countdown = 0;        
        segmentled.DisplayInt(countdown);
        serial.printf("%u\n\r", countdown);
        serial.printf("Hi User! Please enter a number between 2 and 99\n\r");
        serial.scanf("%u", &userinputno);
        segmentled.DisplayInt(userinputno);
        serial.printf("The countdown will now start from %u ... \n\r", userinputno);
           
        wait(3);
        
        startno = userinputno;
    }
}