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.
main.cpp
00001 #include "mbed.h" 00002 #include "menbed.h" 00003 #include "TextLCD.h" 00004 #include "Adafruit_ST7735.h" 00005 00006 Serial pc(USBTX, USBRX); 00007 DigitalIn enable(D2); 00008 //float photocellVoltage(void) {return 0;} 00009 00010 Adafruit_ST7735 tft(D11, D12, D13, D10, D8, D9); // MOSI, MISO, SCLK, SSEL, TFT_DC, TFT_RST 00011 00012 void testlines(uint16_t color); 00013 void testfastlines(uint16_t color1, uint16_t color2); 00014 void IniciandoMaquina(void); 00015 void Alerta(void); 00016 void MenuPrincipal(void); 00017 void Aguarde(void); 00018 void Executando(void); 00019 00020 //Serial pc(USBTX, USBRX); // tx, rx 00021 //I2C i2c_lcd(D14,D15); // SDA, SCL 00022 //TextLCD_I2C lcd(&i2c_lcd, 0x7E, TextLCD::LCD20x4); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type 00023 00024 int main() { 00025 00026 // Use this initializer if you're using a 1.8" TFT 00027 tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab 00028 00029 //iniciando máquina 00030 IniciandoMaquina(); 00031 wait_ms(5000); 00032 Alerta(); 00033 wait_ms(5000); 00034 MenuPrincipal(); 00035 wait_ms(5000); 00036 Aguarde(); 00037 wait_ms(5000); 00038 Executando(); 00039 wait_ms(5000); 00040 //InicioProcessoReferenciamento(); 00041 //wait_ms(5000); 00042 00043 00044 //lcd.setBacklight(TextLCD::LightOn); 00045 00046 // Declare all the submenus so that they can be referenced in the 00047 // definitions of other menus 00048 MenbedMenu *rootMenu; 00049 MenbedMenu *measurementMenu; 00050 MenbedMenu *controlMenu; 00051 MenbedMenu *aboutMenu; 00052 00053 // Root menu--to create a menu, we first create an array of pointers to 00054 // all the menu items that will populate the menu. The MenbedMenuItem 00055 // constructor take five arguments: the function to be executed when the 00056 // item is selected; the child menu to open when the item is selected; 00057 // a boolean indicating whether the child menu is actually this menu's 00058 // ancestor, (useful when creating "go to root menu" items); a parameter 00059 // object that holds a value to be viewed or modified; and a text string 00060 // indicating what the menu item should say. The text string may contain 00061 // a printf-style specifier for a float that is bracketed by \t characters 00062 // to offset it from the surrounding text. If the float specified is 00063 // found, it will be replaced by the value of the parameter. 00064 MenbedMenuItem *rootMenuItems[5] = { 00065 new MenbedMenuItem (NULL, &measurementMenu, false, NULL, "Controle Manual"), // function,child,bollean,data,text 00066 new MenbedMenuItem (NULL, &controlMenu, false, NULL, "Arquivos"), 00067 new MenbedMenuItem (NULL, &aboutMenu, false, NULL, "Configuracoes"), 00068 new MenbedMenuItem (NULL, &rootMenu, false, NULL, "Referenciamento"), 00069 new MenbedMenuItem (NULL, &rootMenu, false, NULL, "Capacitivo"), 00070 }; 00071 // After we have the array of pointers to menu items, we pass the number of 00072 // elements in the arry and the array itself to the MenbedMenu constructor. 00073 rootMenu = new MenbedMenu (5, rootMenuItems); 00074 00075 // Measurements menu--the first item of the measurement menu displays the 00076 // voltage and the resistor divider junction formed between a photocell and 00077 // a fixed resistor. To print this voltage as part of a menu item, we 00078 // create a MenbedMenuParam object that takes as arguments to its 00079 // constructor: a pointer to a function that returns a float containing the 00080 // value of the parameter; a pointer to a function that we would call to 00081 // change the value of the parameter; a boolean (irrevelant here) 00082 // indicating whether the parameter, if it were modifiable by the user, 00083 // should be updated as the user is changing its value or whether its 00084 // should only be updated after the user has confirmed the new value; a 00085 // minimum value for the parameter; a maximum value; and a step size. 00086 //MenbedMenuParam photocellParam (photocellVoltage, NULL, false, 0.0, 0.0, 0.0); 00087 00088 // Having created the parameter, we pass it as the 4th argument of the 00089 // MenbedMenuItem constructor. Note the \t-offset %.2f format specified 00090 // in the menu item text. The menu system will call the photocellVoltage 00091 // function specified in the parameter constructor above and then print the 00092 // float that it returns in place of the %.2f in the menu text. 00093 00094 MenbedMenuItem *measurementMenuItems[2] = { 00095 //new MenbedMenuItem (NULL, NULL, false, &photocellParam, "Photocell: \t%.2f\tV"), 00096 new MenbedMenuItem (NULL, &rootMenu, true, NULL, "lee") }; 00097 measurementMenu = new MenbedMenu (2, measurementMenuItems); 00098 00099 // Controls menu--We have modifiable parameters in the first and second 00100 // meu items of the controls menu. Walking through the first parameter 00101 // constructor, the getLed1Pwm function pointer points to a function that 00102 // returns the current value of the PWM duty cycle. The setLed1Pwm 00103 // function pointer points to a function which sets the PWM duty cycle. 00104 // The boolean set to true indicates that as soon as the user makes a 00105 // change to the parameter, the setLed1Pwm function will be called. The 00106 // menu system will not wait for the user to confirm his change before 00107 // making the call. The 0.0 and 100.0 represent the minimum and 00108 // maximum PWM values. The final 1.0 paramter is the step size when 00109 // changing the PWM duty cycle. 00110 // MenbedMenuParam pwmParam1 (getLed1Pwm, setLed1Pwm, true, 0.0, 100.0, 1.0); 00111 // The only different in this parameter from the one above is that the PWM 00112 // duty cycle is not updated (setLed2Pwm is not called) until the user 00113 // confirms the new duty cycle. If the user cancels his modifications 00114 // (either by pushing the cancel button or pushing and holding the select 00115 // button) setLed2PWM is never called. 00116 // MenbedMenuParam pwmParam2 (getLed2Pwm, setLed2Pwm, false, 0.0, 100.0, 1.0); 00117 // The third, fourth, and fifth items of the control menu demonstrate 00118 // functions when a menu item is selected. The ability to call a function 00119 // can be combined with either displaying a submenu or editing a parameter. 00120 MenbedMenuItem *controlMenuItems[6] = { 00121 // new MenbedMenuItem (NULL, NULL, false, &pwmParam1, "LED1 PWM: \t%.0f\t%"), 00122 // new MenbedMenuItem (NULL, NULL, false, &pwmParam2, "LED2 PWM: \t%.0f\t%"), 00123 // new MenbedMenuItem (toggleLed3, NULL, false, NULL, "Toggle LED3"), 00124 // new MenbedMenuItem (lightLed4, NULL, false, NULL, "Light LED4"), 00125 // new MenbedMenuItem (extinguishLed4, NULL, false, NULL, "Extinguish LED4"), 00126 new MenbedMenuItem (NULL, &rootMenu, true, NULL, "Home") }; 00127 controlMenu = new MenbedMenu (6, controlMenuItems); 00128 00129 // About menu--there's nothing fancy here, but the lack of a "Home" item 00130 // forces the user to employ the cancel button, either directly or by 00131 // pushing and hold the select button, to return to the root menu. 00132 MenbedMenuItem *aboutMenuItems[3] = { 00133 new MenbedMenuItem (NULL, NULL, false, NULL, " NXP3915"), 00134 new MenbedMenuItem (NULL, NULL, false, NULL, " Copyright 2011"), 00135 new MenbedMenuItem (NULL, NULL, false, NULL, " xxxxxxxx@xxx.xxx") }; 00136 aboutMenu = new MenbedMenu (3, aboutMenuItems); 00137 00138 // Having created the menus, menu items, and item parameters, we are ready 00139 // to instantiate the display. MenbedDisplayHD44780 extends MenbedDisplay 00140 // and implements the all-important writeLine function allong with some 00141 // other less important functions. The pins we pass to the constructor 00142 // specify the physical interface connection to the LCD. 00143 MenbedDisplayHD44780 *hd44780Lcd = new MenbedDisplayHD44780 00144 (D8, D9, D4, D5, D6, D7, MenbedDisplayHD44780::LCD20x4); 00145 00146 // Now, we have the menu objects and the display object. All we have to do 00147 // is create the menbed menu system. The number of buttons used by the 00148 // menu system is specified by the number of pins passed to the Menbed 00149 // constructor. The pin order is select, down, up, cancel. With 00150 // constructor overloading, we can opt out of using the cancel and up 00151 // buttons. 00152 00153 /* Four buttons (select, down, up, cancel ) */ 00154 Menbed menbed(D10, D11, D12, D13, 00155 rootMenu, 00156 hd44780Lcd); 00157 } 00158 00159 void testlines(uint16_t color) 00160 { 00161 tft.fillScreen(ST7735_BLACK); 00162 for (int16_t x=0; x < tft.width(); x+=6) { 00163 tft.drawLine(0, 0, x, tft.height()-1, color); 00164 } 00165 for (int16_t y=0; y < tft.height(); y+=6) { 00166 tft.drawLine(0, 0, tft.width()-1, y, color); 00167 } 00168 00169 tft.fillScreen(ST7735_BLACK); 00170 for (int16_t x=0; x < tft.width(); x+=6) { 00171 tft.drawLine(tft.width()-1, 0, x, tft.height()-1, color); 00172 } 00173 for (int16_t y=0; y < tft.height(); y+=6) { 00174 tft.drawLine(tft.width()-1, 0, 0, y, color); 00175 } 00176 00177 tft.fillScreen(ST7735_BLACK); 00178 for (int16_t x=0; x < tft.width(); x+=6) { 00179 tft.drawLine(0, tft.height()-1, x, 0, color); 00180 } 00181 for (int16_t y=0; y < tft.height(); y+=6) { 00182 tft.drawLine(0, tft.height()-1, tft.width()-1, y, color); 00183 } 00184 00185 tft.fillScreen(ST7735_BLACK); 00186 for (int16_t x=0; x < tft.width(); x+=6) { 00187 tft.drawLine(tft.width()-1, tft.height()-1, x, 0, color); 00188 } 00189 for (int16_t y=0; y < tft.height(); y+=6) { 00190 tft.drawLine(tft.width()-1, tft.height()-1, 0, y, color); 00191 } 00192 } 00193 00194 void testfastlines(uint16_t color1, uint16_t color2) 00195 { 00196 tft.fillScreen(ST7735_BLACK); 00197 for (int16_t y=0; y < tft.height(); y+=5) { 00198 tft.drawFastHLine(0, y, tft.width(), color1); 00199 } 00200 for (int16_t x=0; x < tft.width(); x+=5) { 00201 tft.drawFastVLine(x, 0, tft.height(), color2); 00202 } 00203 } 00204 00205 00206 00207 void IniciandoMaquina() 00208 { 00209 tft.setTextWrap(true); 00210 tft.fillScreen(ST7735_BLACK); 00211 int x = 0; 00212 while(x < 5) { 00213 tft.fillScreen(ST7735_BLACK); 00214 tft.setCursor(0,50); 00215 tft.setTextColor(ST7735_WHITE); 00216 tft.setTextSize(2); 00217 tft.printf("Iniciando Pet-Finder"); 00218 tft.setCursor(0,100); 00219 tft.printf("Aguarde"); 00220 wait_ms(100); 00221 tft.fillScreen(ST7735_BLACK); 00222 tft.setCursor(0,50); 00223 tft.setTextColor(ST7735_WHITE); 00224 tft.setTextSize(2); 00225 tft.printf("Iniciando Pet-Finder"); 00226 tft.setCursor(0,100); 00227 tft.printf("Aguarde..."); 00228 wait_ms(100); 00229 x += 1; 00230 } 00231 } 00232 00233 00234 00235 void Alerta() { 00236 tft.setTextWrap(true); 00237 int x = 0; 00238 while(x < 10) { 00239 tft.fillScreen(ST7735_BLACK); 00240 tft.setCursor(0,50); 00241 tft.setTextColor(ST7735_WHITE); 00242 tft.setTextSize(2); 00243 tft.printf("!!ALERTA!!"); 00244 wait_ms(200); 00245 tft.fillScreen(ST7735_RED); 00246 tft.setTextSize(2); 00247 tft.printf("!!ALERTA!!"); 00248 wait_ms(300); 00249 x += 1; 00250 } 00251 00252 } 00253 00254 void MenuPrincipal() { 00255 tft.fillScreen(ST7735_BLACK); 00256 tft.setCursor(0,0); 00257 tft.setTextColor(ST7735_WHITE); 00258 tft.setTextSize(2); 00259 tft.printf("Pet-Finder"); 00260 tft.setCursor(0,40); 00261 tft.printf("Data:"); 00262 tft.setCursor(0,55); 00263 tft.printf("15/05/2017"); 00264 tft.setCursor(0,80); 00265 tft.printf("Horario:"); 00266 tft.setCursor(0,95); 00267 tft.printf("17h27"); 00268 wait_ms(200); 00269 00270 } 00271 00272 void Aguarde() { 00273 int x = 0; 00274 while(x < 5) { 00275 tft.fillScreen(ST7735_BLACK); 00276 tft.setCursor(0,70); 00277 tft.setTextSize(2); 00278 tft.printf("Aguarde..."); 00279 wait_ms(800); 00280 x += 1; 00281 } 00282 } 00283 00284 void Executando() { 00285 int x = 0; 00286 tft.fillScreen(ST7735_WHITE); 00287 tft.setTextColor(ST7735_BLACK); 00288 while(x < 3) { 00289 tft.fillScreen(ST7735_GREEN); 00290 tft.setCursor(0,70); 00291 tft.setTextSize(2); 00292 tft.printf("Executando"); 00293 wait_ms(800); 00294 tft.fillScreen(ST7735_WHITE); 00295 tft.setTextColor(ST7735_BLACK); 00296 tft.setCursor(0,70); 00297 tft.printf("Executando"); 00298 wait_ms(400); 00299 x += 1; 00300 00301 } 00302 tft.fillScreen(ST7735_GREEN); 00303 tft.setCursor(0,70); 00304 tft.printf("Executando"); 00305 } 00306 00307 00308 // ---------------------------------------------------------------------------------------------------------------- 00309 00310 00311
Generated on Thu Jul 14 2022 12:14:44 by
