bo barry
/
Menu
Simple Menu Program for the Application Board LCD
main.cpp
- Committer:
- bobarry
- Date:
- 2014-01-12
- Revision:
- 0:386952ad9742
File content as of revision 0:386952ad9742:
// A simple menu program, displaying on the mbed Application Board // Ideas on how to eliminate the 6 warnings would be appreciated! // Bo Barry 1/11/2014 (My first 'published' program) #include "mbed.h" DigitalOut myled(LED1); #include "C12832_lcd.h" C12832_LCD lcd; #include <stdio.h> void load_menu(void); void sum(void); void rest(void); int main(void) { lcd.locate(0,2); lcd.cls(); lcd.printf("mbed Application Board!"); wait(2); load_menu(); return 0; } void load_menu(void) { int choice; do { lcd.locate(0,2); lcd.cls(); lcd.printf("Menu\n"); lcd.printf("1. Sum 2. Rest 3. Exit\n"); scanf("%d",&choice); switch(choice) { case 1: sum(); break; case 2: rest(); break; case 3: lcd.locate(0,2); lcd.cls(); lcd.printf("Quitting program!"); exit(0); break; default: lcd.printf("Invalid choice!"); break; } } while (choice != 3); } void sum(void) { int num1, num2; // int ch; printf("Enter number 1: "); scanf("%d",&num1); lcd.locate(0,2); lcd.cls(); printf("Enter number 2: "); scanf("%d",&num2); lcd.locate(0,2); lcd.cls(); printf("The sum of the numbers was: %d",num1+num2); wait(2); // Flushes input buffer from the newline from scanf() // while ( (ch = getchar()) != '\n' && ch != EOF) ; lcd.locate(0,2); lcd.cls(); printf("Press ENTER to continue."); // while ( (ch = getchar()) != '\n' && ch != EOF); return; } void rest(void) { lcd.locate(0,2); lcd.cls(); // int ch; printf("Sleepy sleepy... zZZzZzZz\n"); wait(2); printf("You now feel awake again!"); wait(2); // Flushes input buffer // while ((ch = getchar()) != '\n' && ch != EOF) ; lcd.locate(0,2); lcd.cls(); printf("Press ENTER to continue."); // while ((ch = getchar()) != '\n' && ch != EOF); return; }