Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: N5110 ShiftReg Tone mbed
Fork of 1620_Project_Template by
main.cpp
00001 #include "main.h" 00002 00003 // objects defined here with pin numbers (if required) 00004 DigitalIn button_a(p29); 00005 DigitalIn button_b(p28); 00006 DigitalIn button_c(p27); 00007 DigitalIn button_d(p26); 00008 00009 00010 00011 N5110 lcd(p8,p9,p10,p11,p13,p21); 00012 BusOut leds(LED4,LED3,LED2,LED1); 00013 00014 AnalogIn ldr(p15); 00015 00016 PwmOut red_led(p24); 00017 PwmOut green_led(p23); 00018 PwmOut blue_led(p22); 00019 00020 AnalogIn tmp36(p16); 00021 00022 AnalogIn pot_0(p20); 00023 AnalogIn pot_1(p19); 00024 AnalogIn pot_2(p17); 00025 00026 Tone speaker(p18); 00027 ShiftReg shift; 00028 00029 00030 int main() 00031 { 00032 init(); // initialise peripherals 00033 welcome(); // display welcome message 00034 00035 while(1) { // infinite loop 00036 00037 print_menu(); // this re-prints the menu at the start of every loop 00038 00039 // if any buttons pressed then jump to appropriate menu function 00040 if (button_a.read() == 1) { 00041 mode_A(); 00042 } 00043 if (button_b.read() == 1) { 00044 mode_B(); 00045 } 00046 if (button_c.read() == 1) { 00047 mode_C(); 00048 } 00049 if (button_d.read() == 1) { 00050 mode_D(); 00051 } 00052 00053 // delay to prevent multiple button presses being detected 00054 wait_ms(250); 00055 00056 }lcd.clear(); 00057 } 00058 00059 void init() 00060 { 00061 // turn off LEDs 00062 red_led = 1.0; 00063 green_led = 1.0; 00064 blue_led = 1.0; 00065 00066 // turn off 7-seg display 00067 shift.write(0x00); 00068 00069 // initialise LCD 00070 lcd.init(); 00071 00072 // PCB has external pull-down resistors so turn the internal ones off 00073 button_a.mode(PullNone); 00074 button_b.mode(PullNone); 00075 button_c.mode(PullNone); 00076 button_d.mode(PullNone); 00077 } 00078 00079 void print_menu() 00080 { 00081 lcd.clear(); 00082 lcd.printString("Press button",0,0); 00083 lcd.printString("to select",0,1); 00084 lcd.printString("A: Mode A",0,2); 00085 lcd.printString("B: Mode B",0,3); 00086 lcd.printString("C: Mode C",0,4); 00087 lcd.printString("D: Mode D",0,5); 00088 lcd.refresh(); 00089 } 00090 00091 void welcome() 00092 { 00093 lcd.clear(); 00094 lcd.printString(" Automotive",0,0); 00095 lcd.printString(" Electronics",0,1); 00096 lcd.printString(" Simulator",0,2); 00097 lcd.printString(" Al Husien",0,3); 00098 lcd.printString(" Dabashi",0,4); 00099 lcd.printString(" 201042563",0,5); 00100 lcd.refresh(); 00101 wait(5.0); 00102 }
Generated on Wed Jul 13 2022 07:12:38 by
1.7.2
