├── .gitignore ├── LICENSE ├── README.md ├── SimpleMenu.cpp ├── SimpleMenu.h ├── examples ├── LCD │ └── LCD.ino ├── Simple_Menu │ └── Simple_Menu.ino └── other │ └── other.ino └── keywords.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Tinkers Projects 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LCD-Simple-Menu 2 | this library is still under testing 3 | 4 | [https://tinkersprojects.com/](https://tinkersprojects.com/) 5 | 6 | This is a simple LCD Menu Library for Arduino to make menus to control robots and machines. 7 | 8 | Menu Systems on an LCD has always been a thing that has gotten in the way of developing software for robots and machines. It always takes too long to implement and debug. sometimes most of the bugs are from the menu. This library is here to try and simplify the LCD menu but still giving control to the software. 9 | 10 | 11 | ## How It Works 12 | 13 | 14 | 15 | 16 | ## Functions and Varables 17 | ### Menu/Sub-Menu Setup 18 | Different menus, sub-menus or menu items have different setup requiaments. the different types are listed below. 19 | 20 | #### SimpleMenu(int _numberMenuItems, SimpleMenu *_submenus); 21 | **used as Top Menu** 22 | 23 | 24 | 25 | #### SimpleMenu(String _name,int _numberMenuItems, SimpleMenu *_submenus); 26 | **used as Sub-Menu** 27 | 28 | 29 | 30 | #### SimpleMenu(String _name,int *_value); 31 | **used as Value Menu Item** 32 | 33 | 34 | 35 | #### SimpleMenu(String _name,int *_value, int _min, int _max); 36 | **used as Value Menu Item with min and max** 37 | 38 | 39 | 40 | #### SimpleMenu(String _name, void (*_CallBack)()); 41 | **used as function Menu Item** 42 | 43 | 44 | 45 | 46 | ### Menu Setup 47 | #### void begin(void (*_displayCallBack)(SimpleMenu *_menu)); 48 | 49 | 50 | 51 | #### void begin(void (*_displayCallBack)(SimpleMenu *_menu),void (*_valueCallBack)(SimpleMenu *_menu)); 52 | 53 | 54 | 55 | 56 | ### Menu Controls 57 | #### void select(); 58 | 59 | 60 | 61 | #### void back(); 62 | 63 | 64 | 65 | #### void up(); 66 | 67 | 68 | 69 | #### void down(); 70 | 71 | 72 | 73 | #### void index(int _index); 74 | 75 | 76 | 77 | 78 | ### Menu Functions 79 | #### SimpleMenu *next(); 80 | 81 | 82 | 83 | #### SimpleMenu *next(int index); 84 | 85 | 86 | 87 | #### void print(); 88 | 89 | 90 | 91 | #### int hasValue(); 92 | 93 | #### int getValue(); 94 | 95 | 96 | ### Menu Variables 97 | #### String name; 98 | 99 | 100 | 101 | 102 | ## Examples 103 | ### Examples 1: 104 | ```c++ 105 | #include 106 | int valueA, valueB, valueC, mainValue; 107 | void function(); 108 | 109 | SimpleMenu MenuSub[3] = { 110 | SimpleMenu("varable A",&valueA), 111 | SimpleMenu("varable B",&valueB), 112 | SimpleMenu("varable C",&valueC) 113 | }; 114 | 115 | SimpleMenu Menu[3] = { 116 | SimpleMenu("varable",&mainValue), 117 | SimpleMenu("functions",&function), 118 | SimpleMenu("sub menu",MenuSub) 119 | }; 120 | 121 | SimpleMenu TopMenu(3,Menu); 122 | 123 | 124 | void setup() 125 | { 126 | TopMenu.begin(display,displayValue); 127 | } 128 | 129 | void loop() 130 | { 131 | 132 | } 133 | 134 | void function() 135 | { 136 | 137 | } 138 | 139 | 140 | void display(SimpleMenu *_menu) 141 | { 142 | 143 | } 144 | 145 | void displayValue(SimpleMenu *_menu) 146 | { 147 | 148 | } 149 | ``` 150 | 151 | ### Examples 2: 152 | ```c++ 153 | #include 154 | int valueA, valueB, valueC, mainValue; 155 | void function(); 156 | 157 | SimpleMenu MenuSub[3] = { 158 | SimpleMenu("varable A",&valueA), 159 | SimpleMenu("varable B",&valueB), 160 | SimpleMenu("varable C",&valueC) 161 | }; 162 | 163 | SimpleMenu Menu[4] = { 164 | SimpleMenu("varable",&mainValue), 165 | SimpleMenu("functions",function), 166 | SimpleMenu("sub menu A",3,MenuSub), 167 | SimpleMenu("sub menu B",3,MenuSub) 168 | }; 169 | 170 | SimpleMenu TopMenu(4,Menu); 171 | 172 | void display(SimpleMenu *_menu) 173 | { 174 | Serial.print("name: "); 175 | Serial.println(_menu->name); 176 | } 177 | 178 | void displayValue(SimpleMenu *_menu) 179 | { 180 | Serial.println("123"); 181 | } 182 | 183 | 184 | void setup() 185 | { 186 | Serial.begin(9600); 187 | Serial.println("start"); 188 | delay(100); 189 | TopMenu.begin(display,displayValue); 190 | Serial.println(); 191 | TopMenu.select(); 192 | Serial.println(); 193 | TopMenu.select(); 194 | Serial.println(); 195 | TopMenu.up(); 196 | Serial.println(); 197 | TopMenu.up(); 198 | Serial.println(); 199 | TopMenu.up(); 200 | Serial.println(); 201 | TopMenu.select(); 202 | Serial.println(); 203 | 204 | Serial.println("finish"); 205 | } 206 | 207 | void loop() 208 | { 209 | 210 | } 211 | 212 | void function() 213 | { 214 | Serial.println("function"); 215 | } 216 | 217 | 218 | ``` 219 | 220 | ### Examples 3: 221 | ```c++ 222 | #include 223 | #include 224 | 225 | #define LCD_RS 2 226 | #define LCD_EN 4 227 | #define LCD_D4 5 228 | #define LCD_D5 6 229 | #define LCD_D6 7 230 | #define LCD_D7 8 231 | 232 | int valueA, valueB, valueC, mainValue=5; 233 | void function(); 234 | 235 | SimpleMenu MenuSub[3] = { 236 | SimpleMenu("varable A",&valueA), 237 | SimpleMenu("varable B",&valueB), 238 | SimpleMenu("varable C",&valueC) 239 | }; 240 | 241 | SimpleMenu Menu[4] = { 242 | SimpleMenu("varable",&mainValue,3,10), 243 | SimpleMenu("functions",function), 244 | SimpleMenu("sub menu A",3,MenuSub), 245 | SimpleMenu("sub menu B",3,MenuSub) 246 | }; 247 | 248 | SimpleMenu TopMenu(4,Menu); 249 | LiquidCrystal lcd = LiquidCrystal(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7); 250 | 251 | void display(SimpleMenu *_menu) 252 | { 253 | lcd.clear(); 254 | lcd.print(">"); 255 | lcd.print(_menu->name); 256 | 257 | SimpleMenu *next = TopMenu.next(); 258 | if(next != NULL) 259 | { 260 | lcd.setCursor(1,1); 261 | lcd.print(next->name); 262 | } 263 | } 264 | 265 | void displayValue(SimpleMenu *_menu) 266 | { 267 | lcd.clear(); 268 | lcd.print(_menu->name); 269 | lcd.setCursor(0,1); 270 | lcd.print(_menu->getValue()); 271 | } 272 | 273 | 274 | void setup() 275 | { 276 | Serial.begin(9600); 277 | Serial.println("start"); 278 | delay(100); 279 | 280 | lcd.begin(16, 2); 281 | TopMenu.begin(display,displayValue); 282 | } 283 | 284 | void loop() 285 | { 286 | while (Serial.available()) 287 | { 288 | switch( (char)Serial.read()) 289 | { 290 | case 'w': 291 | TopMenu.up(); 292 | break; 293 | case 's': 294 | TopMenu.down(); 295 | break; 296 | case 'a': 297 | TopMenu.back(); 298 | break; 299 | case 'd': 300 | TopMenu.select(); 301 | break; 302 | } 303 | } 304 | } 305 | 306 | void function() 307 | { 308 | lcd.clear(); 309 | lcd.print("function"); 310 | Serial.print("function"); 311 | delay(3000); 312 | } 313 | 314 | ``` 315 | 316 | 317 | ## To Be Developed 318 | - adding lists for files from SD card or varables. 319 | -------------------------------------------------------------------------------- /SimpleMenu.cpp: -------------------------------------------------------------------------------- 1 | /********************************************************************************************** 2 | * Arduino LED RGB Library - version 2.0 3 | * by William Bailes http://tinkersprojects.com/ 4 | * 5 | * This Library is licensed under a GPLv3 License 6 | **********************************************************************************************/ 7 | 8 | #if ARDUINO >= 100 9 | #include "Arduino.h" 10 | #else 11 | #include "WProgram.h" 12 | #endif 13 | 14 | #include "SimpleMenu.h" 15 | 16 | /******************* SETUP *******************/ 17 | 18 | SimpleMenu::SimpleMenu(int _numberMenuItems, SimpleMenu *_submenus) //defult 19 | { 20 | numberMenuItems = _numberMenuItems; 21 | submenus = _submenus; 22 | } 23 | 24 | SimpleMenu::SimpleMenu(void (*_CallBack)()) //defult 25 | { 26 | CallBack = _CallBack; 27 | } 28 | 29 | 30 | SimpleMenu::SimpleMenu( bool (*_ListCallBack)(int index), SimpleMenu *_subListmenus) //List menu with function 31 | { 32 | subListmenus = _subListmenus; 33 | ListCallBack = _ListCallBack; 34 | } 35 | 36 | SimpleMenu::SimpleMenu( bool (*_ListCallBack)(int index), void (*_CallBack)()) //List menu with function 37 | { 38 | CallBack = _CallBack; 39 | ListCallBack = _ListCallBack; 40 | } 41 | 42 | SimpleMenu::SimpleMenu(String _name,int _numberMenuItems, SimpleMenu *_submenus) //sub menu 43 | { 44 | name = _name; 45 | numberMenuItems = _numberMenuItems; 46 | submenus = _submenus; 47 | } 48 | 49 | SimpleMenu::SimpleMenu(String _name,int *_value) //Value menu 50 | { 51 | name = _name; 52 | value = _value; 53 | } 54 | 55 | SimpleMenu::SimpleMenu(String _name,int *_value, int _min, int _max) //Value menu 56 | { 57 | name = _name; 58 | value = _value; 59 | min = _min; 60 | max = _max; 61 | minMaxSet = true; 62 | } 63 | 64 | SimpleMenu::SimpleMenu(String _name, void (*_CallBack)()) //function menu 65 | { 66 | name = _name; 67 | CallBack = _CallBack; 68 | } 69 | 70 | SimpleMenu::SimpleMenu(String _name, bool (*_ListCallBack)(int index), SimpleMenu *_subListmenus) //List menu with function 71 | { 72 | name = _name; 73 | subListmenus = _subListmenus; 74 | ListCallBack = _ListCallBack; 75 | } 76 | 77 | SimpleMenu::SimpleMenu(String _name, bool (*_ListCallBack)(int index), void (*_CallBack)()) //List menu with function 78 | { 79 | name = _name; 80 | CallBack = _CallBack; 81 | ListCallBack = _ListCallBack; 82 | } 83 | 84 | void SimpleMenu::begin() 85 | { 86 | selectMenu = false; 87 | menuLocation = 0; 88 | this->print(); 89 | } 90 | 91 | void SimpleMenu::begin(void (*_displayCallBack)(SimpleMenu *_menu)) 92 | { 93 | selectMenu = false; 94 | menuLocation = 0; 95 | if(displayCallBack == NULL) 96 | displayCallBack = _displayCallBack; 97 | this->print(); 98 | } 99 | 100 | void SimpleMenu::begin(void (*_displayCallBack)(SimpleMenu *_menu),void (*_valueCallBack)(SimpleMenu *_menu)) 101 | { 102 | selectMenu = false; 103 | menuLocation = 0; 104 | if(displayCallBack == NULL) 105 | displayCallBack = _displayCallBack; 106 | if(valueCallBack == NULL) 107 | valueCallBack = _valueCallBack; 108 | this->print(); 109 | } 110 | 111 | void SimpleMenu::begin(SimpleMenu *_Top,void (*_displayCallBack)(SimpleMenu *_menu),void (*_valueCallBack)(SimpleMenu *_menu)) 112 | { 113 | selectMenu = false; 114 | menuLocation = 0; 115 | Top_menu = _Top; 116 | 117 | if(displayCallBack == NULL) 118 | displayCallBack = _displayCallBack; 119 | if(valueCallBack == NULL) 120 | valueCallBack = _valueCallBack; 121 | 122 | if(CallBack != NULL && ListCallBack == NULL) 123 | { 124 | CallBack(); 125 | Top_menu->returned(); 126 | } 127 | 128 | this->print(); 129 | } 130 | 131 | void SimpleMenu::setFunctions(void (*_displayCallBack)(SimpleMenu *_menu),void (*_valueCallBack)(SimpleMenu *_menu)) 132 | { 133 | displayCallBack = _displayCallBack; 134 | valueCallBack = _valueCallBack; 135 | } 136 | 137 | void SimpleMenu::home() 138 | { 139 | if(subListmenus != NULL) 140 | { 141 | subListmenus->back(); 142 | } 143 | if(submenus != NULL) 144 | { 145 | submenus[menuLocation].back(); 146 | } 147 | if(selectMenu) 148 | { 149 | selectMenu=false; 150 | } 151 | this->print(); 152 | } 153 | 154 | void SimpleMenu::select() 155 | { 156 | if(menuLocation == -1) 157 | { 158 | Top_menu->returned(); 159 | } 160 | else if(CallBack != NULL && ListCallBack != NULL) 161 | { 162 | CallBack(); 163 | } 164 | else if(selectMenu && submenus != NULL) 165 | { 166 | submenus[menuLocation].select(); 167 | } 168 | else if(submenus != NULL) 169 | { 170 | selectMenu = true; 171 | submenus[menuLocation].begin(this,displayCallBack,valueCallBack); 172 | } 173 | else if(selectMenu && subListmenus != NULL) 174 | { 175 | subListmenus->select(); 176 | } 177 | else if(subListmenus != NULL) 178 | { 179 | selectMenu = true; 180 | subListmenus->begin(this,displayCallBack,valueCallBack); 181 | } 182 | else if(value != NULL && Top_menu != NULL) 183 | { 184 | Top_menu->returned(); 185 | } 186 | this->print(); 187 | } 188 | 189 | void SimpleMenu::back() 190 | { 191 | if(selectMenu && subListmenus != NULL && subListmenus->selectMenu) 192 | { 193 | subListmenus->back(); 194 | } 195 | else if(selectMenu && submenus != NULL && submenus[menuLocation].selectMenu) 196 | { 197 | submenus[menuLocation].back(); 198 | } 199 | else if(submenus != NULL) 200 | { 201 | selectMenu = false; 202 | } 203 | else if(Top_menu != NULL) 204 | { 205 | Top_menu->returned(); 206 | } 207 | this->print(); 208 | } 209 | 210 | void SimpleMenu::returned() 211 | { 212 | selectMenu = false; 213 | this->print(); 214 | } 215 | 216 | void SimpleMenu::up() 217 | { 218 | if(selectMenu && subListmenus != NULL) 219 | { 220 | subListmenus->up(); 221 | } 222 | else if(selectMenu) 223 | { 224 | submenus[menuLocation].up(); 225 | } 226 | else if(value != NULL) 227 | { 228 | *value = *value + 1; 229 | } 230 | else 231 | { 232 | menuLocation--; 233 | } 234 | this->print(); 235 | } 236 | 237 | void SimpleMenu::down() 238 | { 239 | if(selectMenu && subListmenus != NULL) 240 | { 241 | subListmenus->down(); 242 | } 243 | else if(selectMenu) 244 | { 245 | submenus[menuLocation].down(); 246 | } 247 | else if(value != NULL) 248 | { 249 | *value = *value - 1; 250 | } 251 | else 252 | { 253 | menuLocation++; 254 | } 255 | this->print(); 256 | } 257 | 258 | void SimpleMenu::index(int _index) 259 | { 260 | 261 | if(selectMenu && subListmenus != NULL) 262 | { 263 | subListmenus->index(_index); 264 | } 265 | else if(selectMenu) 266 | { 267 | submenus[menuLocation].index(_index); 268 | } 269 | else if(value != NULL) 270 | { 271 | *value = _index; 272 | } 273 | else 274 | { 275 | menuLocation = _index; 276 | } 277 | this->print(); 278 | } 279 | 280 | SimpleMenu *SimpleMenu::next() 281 | { 282 | return this->next(1); 283 | } 284 | 285 | SimpleMenu *SimpleMenu::next(int index) 286 | { 287 | if(selectMenu && submenus != NULL) 288 | { 289 | return submenus[menuLocation].next(index); 290 | } 291 | else if(menuLocation+index>=0 && menuLocation+index < numberMenuItems) 292 | { 293 | return &submenus[menuLocation+index]; 294 | } 295 | else if(selectMenu && subListmenus != NULL) 296 | { 297 | return subListmenus->next(index); 298 | } 299 | return NULL; 300 | } 301 | 302 | void SimpleMenu::print() 303 | { 304 | if(minMaxSet && *valuemax) 310 | { 311 | *value = max; 312 | } 313 | 314 | if(/*ListCallBack == NULL &&*/ menuLocation<0) 315 | { 316 | menuLocation = 0; 317 | } 318 | 319 | 320 | if(submenus != NULL && menuLocation >= numberMenuItems) 321 | { 322 | menuLocation = numberMenuItems-1; 323 | } 324 | 325 | if(selectMenu && submenus != NULL ) 326 | { 327 | submenus[menuLocation].print(); 328 | } 329 | else if(selectMenu && subListmenus != NULL && ListCallBack != NULL ) 330 | { 331 | subListmenus->print(); 332 | } 333 | else if(value != NULL) 334 | { 335 | valueCallBack(this); 336 | } 337 | else if(ListCallBack != NULL) 338 | { 339 | bool LocationExists = ListCallBack(menuLocation); 340 | while(LocationExists == false && menuLocation > -1 ) 341 | { 342 | menuLocation--; 343 | LocationExists = ListCallBack(menuLocation); 344 | } 345 | 346 | if(menuLocation < -1) 347 | { 348 | menuLocation = -1; 349 | this->back(); 350 | } 351 | } 352 | else if(submenus != NULL) 353 | { 354 | displayCallBack(&submenus[menuLocation]); 355 | } 356 | 357 | } 358 | 359 | bool SimpleMenu::hasValue() 360 | { 361 | return value != NULL; 362 | } 363 | 364 | int SimpleMenu::getValue() 365 | { 366 | return *value; 367 | } 368 | 369 | 370 | int SimpleMenu::getIndex() 371 | { 372 | return menuLocation; 373 | } 374 | -------------------------------------------------------------------------------- /SimpleMenu.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef SimpleMenu_h 3 | #define SimpleMenu_h 4 | 5 | #if ARDUINO >= 100 6 | #include 7 | #else 8 | #include 9 | #include 10 | #endif 11 | 12 | class SimpleMenu 13 | { 14 | public: 15 | SimpleMenu(int _numberMenuItems, SimpleMenu *_submenus); //defult 16 | SimpleMenu(void (*_CallBack)()); 17 | SimpleMenu(bool (*_ListCallBack)(int index), void (*_CallBack)()); 18 | SimpleMenu(bool (*_ListCallBack)(int index), SimpleMenu *_submenus); 19 | SimpleMenu(String _name,int _numberMenuItems, SimpleMenu *_submenus); //sub menu 20 | SimpleMenu(String _name,int *_value); //Value menu 21 | SimpleMenu(String _name,int *_value, int _min, int _max); //Value menu with min and max 22 | SimpleMenu(String _name, void (*_CallBack)()); //function menu 23 | SimpleMenu(String _name, bool (*_ListCallBack)(int index), SimpleMenu *_submenus); //List menu with function 24 | SimpleMenu(String _name, bool (*_ListCallBack)(int index), void (*_CallBack)()); //List menu with function 25 | 26 | void begin(); 27 | void begin(void (*_displayCallBack)(SimpleMenu *_menu)); 28 | void begin(void (*_displayCallBack)(SimpleMenu *_menu),void (*_valueCallBack)(SimpleMenu *_menu)); 29 | void begin(SimpleMenu *_Top,void (*_displayCallBack)(SimpleMenu *_menu),void (*_valueCallBack)(SimpleMenu *_menu)); 30 | void setFunctions(void (*_displayCallBack)(SimpleMenu *_menu),void (*_valueCallBack)(SimpleMenu *_menu)); 31 | 32 | void home(); 33 | void select(); 34 | void back(); 35 | void returned(); 36 | void up(); 37 | void down(); 38 | void index(int _index); 39 | 40 | SimpleMenu *next(); 41 | SimpleMenu *next(int index); 42 | int getValue(); 43 | bool hasValue(); 44 | int getIndex(); 45 | void print(); 46 | 47 | String name; 48 | bool selectMenu = false; 49 | int menuLocation = 0; 50 | 51 | private: 52 | SimpleMenu *Top_menu = NULL; 53 | 54 | int numberMenuItems; 55 | SimpleMenu *submenus = NULL; 56 | SimpleMenu *subListmenus = NULL; 57 | int *value = NULL; 58 | void (*CallBack) () = NULL; 59 | bool (*ListCallBack)(int index) = NULL; 60 | void (*displayCallBack)(SimpleMenu *_menu) = NULL; 61 | void (*valueCallBack)(SimpleMenu *_menu) = NULL; 62 | 63 | int min; 64 | int max; 65 | bool minMaxSet = false; 66 | }; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /examples/LCD/LCD.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define LCD_RS 2 5 | #define LCD_EN 4 6 | #define LCD_D4 5 7 | #define LCD_D5 6 8 | #define LCD_D6 7 9 | #define LCD_D7 8 10 | 11 | int valueA, valueB, valueC, mainValue=5; 12 | void function(); 13 | 14 | SimpleMenu MenuSub[3] = { 15 | SimpleMenu("varable A",&valueA), 16 | SimpleMenu("varable B",&valueB), 17 | SimpleMenu("varable C",&valueC) 18 | }; 19 | 20 | SimpleMenu Menu[4] = { 21 | SimpleMenu("varable",&mainValue,3,10), 22 | SimpleMenu("functions",function), 23 | SimpleMenu("sub menu A",3,MenuSub), 24 | SimpleMenu("sub menu B",3,MenuSub) 25 | }; 26 | 27 | SimpleMenu TopMenu(4,Menu); 28 | LiquidCrystal lcd = LiquidCrystal(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7); 29 | 30 | void display(SimpleMenu *_menu) 31 | { 32 | lcd.clear(); 33 | lcd.print(">"); 34 | lcd.print(_menu->name); 35 | 36 | SimpleMenu *next = TopMenu.next(); 37 | if(next != NULL) 38 | { 39 | lcd.setCursor(1,1); 40 | lcd.print(next->name); 41 | } 42 | } 43 | 44 | void displayValue(SimpleMenu *_menu) 45 | { 46 | lcd.clear(); 47 | lcd.print(_menu->name); 48 | lcd.setCursor(0,1); 49 | lcd.print(_menu->getValue()); 50 | } 51 | 52 | 53 | void setup() 54 | { 55 | Serial.begin(9600); 56 | Serial.println("start"); 57 | delay(100); 58 | 59 | lcd.begin(16, 2); 60 | TopMenu.begin(display,displayValue); 61 | } 62 | 63 | void loop() 64 | { 65 | while (Serial.available()) 66 | { 67 | switch( (char)Serial.read()) 68 | { 69 | case 'w': 70 | TopMenu.up(); 71 | break; 72 | case 's': 73 | TopMenu.down(); 74 | break; 75 | case 'a': 76 | TopMenu.back(); 77 | break; 78 | case 'd': 79 | TopMenu.select(); 80 | break; 81 | } 82 | } 83 | } 84 | 85 | void function() 86 | { 87 | lcd.clear(); 88 | lcd.print("function"); 89 | Serial.print("function"); 90 | delay(3000); 91 | } 92 | -------------------------------------------------------------------------------- /examples/Simple_Menu/Simple_Menu.ino: -------------------------------------------------------------------------------- 1 | #include 2 | int valueA, valueB, valueC, mainValue; 3 | void function(); 4 | 5 | SimpleMenu MenuSub[3] = { 6 | SimpleMenu("varable A",&valueA), 7 | SimpleMenu("varable B",&valueB), 8 | SimpleMenu("varable C",&valueC) 9 | }; 10 | 11 | SimpleMenu Menu[3] = { 12 | SimpleMenu("varable",&mainValue), 13 | SimpleMenu("functions",&function), 14 | SimpleMenu("sub menu",MenuSub) 15 | }; 16 | 17 | SimpleMenu TopMenu(3,Menu); 18 | 19 | 20 | void setup() 21 | { 22 | TopMenu.begin(display,displayValue); 23 | } 24 | 25 | void loop() 26 | { 27 | 28 | } 29 | 30 | void function() 31 | { 32 | 33 | } 34 | 35 | 36 | void display(SimpleMenu *_menu) 37 | { 38 | 39 | } 40 | 41 | void displayValue(SimpleMenu *_menu) 42 | { 43 | 44 | } -------------------------------------------------------------------------------- /examples/other/other.ino: -------------------------------------------------------------------------------- 1 | #include 2 | int valueA, valueB, valueC, mainValue; 3 | void function(); 4 | 5 | SimpleMenu MenuSub[3] = { 6 | SimpleMenu("varable A",&valueA), 7 | SimpleMenu("varable B",&valueB), 8 | SimpleMenu("varable C",&valueC) 9 | }; 10 | 11 | SimpleMenu Menu[4] = { 12 | SimpleMenu("varable",&mainValue), 13 | SimpleMenu("functions",function), 14 | SimpleMenu("sub menu A",3,MenuSub), 15 | SimpleMenu("sub menu B",3,MenuSub) 16 | }; 17 | 18 | SimpleMenu TopMenu(4,Menu); 19 | 20 | void display(SimpleMenu *_menu) 21 | { 22 | Serial.print("name: "); 23 | Serial.println(_menu->name); 24 | 25 | SimpleMenu *next = TopMenu.next(); 26 | Serial.print("next name: "); 27 | Serial.println(next->name); 28 | } 29 | 30 | void displayValue(SimpleMenu *_menu) 31 | { 32 | Serial.println("123"); 33 | } 34 | 35 | 36 | void setup() 37 | { 38 | Serial.begin(9600); 39 | Serial.println("start"); 40 | delay(100); 41 | TopMenu.begin(display,displayValue); 42 | Serial.println(); 43 | TopMenu.select(); 44 | Serial.println(); 45 | TopMenu.select(); 46 | Serial.println(); 47 | TopMenu.up(); 48 | Serial.println(); 49 | TopMenu.up(); 50 | Serial.println(); 51 | TopMenu.up(); 52 | Serial.println(); 53 | TopMenu.select(); 54 | Serial.println(); 55 | 56 | Serial.println("finish"); 57 | } 58 | 59 | void loop() 60 | { 61 | 62 | } 63 | 64 | void function() 65 | { 66 | 67 | Serial.println("function"); 68 | } 69 | 70 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Library and class (KEYWORD1) 3 | ####################################### 4 | 5 | SimpleMenu KEYWORD1 6 | 7 | 8 | 9 | ####################################### 10 | # Functions (KEYWORD2) 11 | ####################################### 12 | 13 | 14 | 15 | ####################################### 16 | # Constants (LITERAL1) 17 | #######################################\ --------------------------------------------------------------------------------