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
00001 #include "mbed.h" 00002 #include "USBSerial.h" 00003 #include "SevenSegmentDisplay.h" 00004 00005 //Virtual serial port over USB 00006 USBSerial serial; 00007 00008 int countdown; 00009 int startno = 6; 00010 int userinputno; // do not initialise scanf values as this creates problems 00011 00012 SevenSegmentDisplay segmentled( FADE ); 00013 Ticker timeout; 00014 00015 void attimeout(); 00016 00017 int main(void) 00018 { 00019 00020 00021 while(1) 00022 { 00023 wait(1); 00024 for(countdown=startno; countdown>0; countdown--) 00025 { 00026 segmentled.DisplayInt(countdown); 00027 serial.printf("%d\n\r", countdown); 00028 wait(1); 00029 } 00030 00031 countdown = 0; 00032 segmentled.DisplayInt(countdown); 00033 serial.printf("%d\n\r", countdown); 00034 serial.printf("Hi User! Please enter a number between 2 and 99\n\r"); 00035 serial.scanf("%d", &userinputno); 00036 segmentled.DisplayInt(userinputno); 00037 serial.printf("The countdown will now start from %d ... \n\r", userinputno); 00038 00039 wait(1); 00040 00041 startno = userinputno; 00042 } 00043 }
Generated on Thu Jul 28 2022 02:34:01 by 1.7.2