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
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 N5110 lcd(p8,p9,p10,p11,p13,p21); 00010 BusOut leds(LED4,LED3,LED2,LED1); 00011 00012 AnalogIn ldr(p15); 00013 00014 PwmOut red_led(p24); 00015 PwmOut green_led(p23); 00016 PwmOut blue_led(p22); 00017 00018 AnalogIn tmp36(p16); 00019 00020 AnalogIn pot_0(p20); 00021 AnalogIn pot_1(p19); 00022 AnalogIn pot_2(p17); 00023 00024 Tone speaker(p18); 00025 ShiftReg shift; 00026 00027 int main() 00028 { 00029 init(); // initialise peripherals 00030 welcome(); // display welcome message 00031 00032 while(1) { // infinite loop 00033 00034 print_menu(); // this re-prints the menu at the start of every loop 00035 00036 // if any buttons pressed then jump to appropriate menu function 00037 if (button_a.read() == 1) { 00038 mode_A(); 00039 } 00040 if (button_b.read() == 1) { 00041 mode_B(); 00042 } 00043 if (button_c.read() == 1) { 00044 mode_C(); 00045 } 00046 if (button_d.read() == 1) { 00047 mode_D(); 00048 } 00049 00050 // delay to prevent multiple button presses being detected 00051 wait_ms(250); 00052 00053 } 00054 } 00055 00056 void init() 00057 { 00058 // turn off LEDs 00059 red_led = 1.0; 00060 green_led = 1.0; 00061 blue_led = 1.0; 00062 00063 // turn off 7-seg display 00064 shift.write(0x00); 00065 00066 // initialise LCD 00067 lcd.init(); 00068 00069 // PCB has external pull-down resistors so turn the internal ones off 00070 button_a.mode(PullNone); 00071 button_b.mode(PullNone); 00072 button_c.mode(PullNone); 00073 button_d.mode(PullNone); 00074 } 00075 00076 void print_menu() 00077 { 00078 lcd.clear(); 00079 lcd.printString("Press button",0,0); 00080 lcd.printString("to select",0,1); 00081 lcd.printString("A: Mode A",0,2); 00082 lcd.printString("B: Mode B",0,3); 00083 lcd.printString("C: Mode C",0,4); 00084 lcd.printString("D: Mode D",0,5); 00085 lcd.refresh(); 00086 } 00087 00088 void welcome() 00089 { 00090 lcd.clear(); 00091 lcd.printString(" Automotive",0,0); 00092 lcd.printString(" Electronics",0,1); 00093 lcd.printString(" Simulator",0,2); 00094 lcd.printString("Craig A. Evans",0,4); 00095 lcd.printString(" 0123456789",0,5); 00096 lcd.refresh(); 00097 wait(5.0); 00098 }
Generated on Wed Jul 13 2022 02:46:30 by
1.7.2