this locks like shit
Fork of MenuLCD_copy by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "menbed.h" 00003 #include "TextLCD.h" 00004 00005 Serial pc(USBTX, USBRX); 00006 DigitalOut myled(D14); 00007 void capacitivo(){ 00008 myled=!myled; 00009 } 00010 00011 //float photocellVoltage(void) {return 0;} 00012 00013 //Serial pc(USBTX, USBRX); // tx, rx 00014 //I2C i2c_lcd(D14,D15); // SDA, SCL 00015 //TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type 00016 00017 int main() { 00018 //lcd.setBacklight(TextLCD::LightOn); 00019 00020 // Declare all the submenus so that they can be referenced in the 00021 // definitions of other menus 00022 MenbedMenu *rootMenu; 00023 MenbedMenu *measurementMenu; 00024 MenbedMenu *controlMenu; 00025 MenbedMenu *aboutMenu; 00026 00027 // Root menu--to create a menu, we first create an array of pointers to 00028 // all the menu items that will populate the menu. The MenbedMenuItem 00029 // constructor take five arguments: the function to be executed when the 00030 // item is selected; the child menu to open when the item is selected; 00031 // a boolean indicating whether the child menu is actually this menu's 00032 // ancestor, (useful when creating "go to root menu" items); a parameter 00033 // object that holds a value to be viewed or modified; and a text string 00034 // indicating what the menu item should say. The text string may contain 00035 // a printf-style specifier for a float that is bracketed by \t characters 00036 // to offset it from the surrounding text. If the float specified is 00037 // found, it will be replaced by the value of the parameter. 00038 MenbedMenuItem *rootMenuItems[5] = { 00039 new MenbedMenuItem (NULL, &measurementMenu, false, NULL, "Controle Manual"), // function,child,bollean,data,text 00040 new MenbedMenuItem (capacitivo, &controlMenu, false, NULL, "Arquivos"), 00041 new MenbedMenuItem (NULL, &aboutMenu, false, NULL, "Configuracoes"), 00042 new MenbedMenuItem (NULL, &rootMenu, false, NULL, "Referenciamento"), 00043 new MenbedMenuItem (NULL, &rootMenu, false, NULL, "Capacitivo"), 00044 }; 00045 // After we have the array of pointers to menu items, we pass the number of 00046 // elements in the arry and the array itself to the MenbedMenu constructor. 00047 rootMenu = new MenbedMenu (5, rootMenuItems); 00048 00049 // Measurements menu--the first item of the measurement menu displays the 00050 // voltage and the resistor divider junction formed between a photocell and 00051 // a fixed resistor. To print this voltage as part of a menu item, we 00052 // create a MenbedMenuParam object that takes as arguments to its 00053 // constructor: a pointer to a function that returns a float containing the 00054 // value of the parameter; a pointer to a function that we would call to 00055 // change the value of the parameter; a boolean (irrevelant here) 00056 // indicating whether the parameter, if it were modifiable by the user, 00057 // should be updated as the user is changing its value or whether its 00058 // should only be updated after the user has confirmed the new value; a 00059 // minimum value for the parameter; a maximum value; and a step size. 00060 //MenbedMenuParam photocellParam (photocellVoltage, NULL, false, 0.0, 0.0, 0.0); 00061 00062 // Having created the parameter, we pass it as the 4th argument of the 00063 // MenbedMenuItem constructor. Note the \t-offset %.2f format specified 00064 // in the menu item text. The menu system will call the photocellVoltage 00065 // function specified in the parameter constructor above and then print the 00066 // float that it returns in place of the %.2f in the menu text. 00067 00068 MenbedMenuItem *measurementMenuItems[2] = { 00069 //new MenbedMenuItem (NULL, NULL, false, &photocellParam, "Photocell: \t%.2f\tV"), 00070 new MenbedMenuItem (NULL, &rootMenu, true, NULL, "lee"), 00071 new MenbedMenuItem (capacitivo, NULL, true, NULL, "LED") }; 00072 measurementMenu = new MenbedMenu (2, measurementMenuItems); 00073 00074 // Controls menu--We have modifiable parameters in the first and second 00075 // meu items of the controls menu. Walking through the first parameter 00076 // constructor, the getLed1Pwm function pointer points to a function that 00077 // returns the current value of the PWM duty cycle. The setLed1Pwm 00078 // function pointer points to a function which sets the PWM duty cycle. 00079 // The boolean set to true indicates that as soon as the user makes a 00080 // change to the parameter, the setLed1Pwm function will be called. The 00081 // menu system will not wait for the user to confirm his change before 00082 // making the call. The 0.0 and 100.0 represent the minimum and 00083 // maximum PWM values. The final 1.0 paramter is the step size when 00084 // changing the PWM duty cycle. 00085 // MenbedMenuParam pwmParam1 (getLed1Pwm, setLed1Pwm, true, 0.0, 100.0, 1.0); 00086 // The only different in this parameter from the one above is that the PWM 00087 // duty cycle is not updated (setLed2Pwm is not called) until the user 00088 // confirms the new duty cycle. If the user cancels his modifications 00089 // (either by pushing the cancel button or pushing and holding the select 00090 // button) setLed2PWM is never called. 00091 // MenbedMenuParam pwmParam2 (getLed2Pwm, setLed2Pwm, false, 0.0, 100.0, 1.0); 00092 // The third, fourth, and fifth items of the control menu demonstrate 00093 // functions when a menu item is selected. The ability to call a function 00094 // can be combined with either displaying a submenu or editing a parameter. 00095 MenbedMenuItem *controlMenuItems[6] = { 00096 // new MenbedMenuItem (NULL, NULL, false, &pwmParam1, "LED1 PWM: \t%.0f\t%"), 00097 // new MenbedMenuItem (NULL, NULL, false, &pwmParam2, "LED2 PWM: \t%.0f\t%"), 00098 // new MenbedMenuItem (toggleLed3, NULL, false, NULL, "Toggle LED3"), 00099 // new MenbedMenuItem (lightLed4, NULL, false, NULL, "Light LED4"), 00100 // new MenbedMenuItem (extinguishLed4, NULL, false, NULL, "Extinguish LED4"), 00101 new MenbedMenuItem (NULL, &rootMenu, true, NULL, "Home") }; 00102 controlMenu = new MenbedMenu (6, controlMenuItems); 00103 00104 // About menu--there's nothing fancy here, but the lack of a "Home" item 00105 // forces the user to employ the cancel button, either directly or by 00106 // pushing and hold the select button, to return to the root menu. 00107 MenbedMenuItem *aboutMenuItems[3] = { 00108 new MenbedMenuItem (NULL, NULL, false, NULL, " NXP3915"), 00109 new MenbedMenuItem (NULL, NULL, false, NULL, " Copyright 2011"), 00110 new MenbedMenuItem (NULL, NULL, false, NULL, " xxxxxxxx@xxx.xxx") }; 00111 aboutMenu = new MenbedMenu (3, aboutMenuItems); 00112 00113 // Having created the menus, menu items, and item parameters, we are ready 00114 // to instantiate the display. MenbedDisplayHD44780 extends MenbedDisplay 00115 // and implements the all-important writeLine function allong with some 00116 // other less important functions. The pins we pass to the constructor 00117 // specify the physical interface connection to the LCD. 00118 MenbedDisplayHD44780 *hd44780Lcd = new MenbedDisplayHD44780 00119 (D8, D9, D4, D5, D6, D7, MenbedDisplayHD44780::LCD20x4); 00120 00121 // Now, we have the menu objects and the display object. All we have to do 00122 // is create the menbed menu system. The number of buttons used by the 00123 // menu system is specified by the number of pins passed to the Menbed 00124 // constructor. The pin order is select, down, up, cancel. With 00125 // constructor overloading, we can opt out of using the cancel and up 00126 // buttons. 00127 00128 /* Four buttons (select, down, up, cancel ) */ 00129 Menbed menbed(D10, D11, D12, D13, 00130 rootMenu, 00131 hd44780Lcd); 00132 while(1) {} 00133 } 00134 00135
Generated on Tue Jul 12 2022 22:15:03 by
1.7.2
