Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Console menu
Author | Message | ||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Playing with the idea of being able to control my MM from the console as well as the touch screen, so it I want to change something remotely, from a terminal app on my phone, I can. Looked over a few related threads, but looking for suggestions as to if I'm on the right track, or taking the wrong approach. The few bits of code I've added:- Do
IF INKEY$="m" THEN DoMenu . . . . . LOOP Sub DoMenu 'Output Stuff to console for debugging purposes Print Esc+"[2J"; Print Esc+"[f"; Print "1. Change Target Temperature" Print "2. Change Differential" Print "3. Change Solar Level" Print "9. Stop & Shutdown" Print "0. Exit" pause 5000 Print Esc+"[2J"; End sub Normally the console displays some data similar to this, but relevant to the appliation:- DS18B20 Number 1 Temp 21.25 DS18B20 Number 2 Temp 21.87 DS18B20 Number 3 Temp 21.81 Thermistor Voltage = 1.77 Thermistor Resistance = 9497.47 Thermistor Temp Beta Coeff 21.23 Thermistor Temp Steinhart 21.28 Device Time is 07:51:20 I've got as far as changing it to display this, if I press the "m" key in the console:- Options Menu. 1. Change Target Temperature 2. Change Differential 3. Change Solar Level 9. Stop & Shutdown 0. Exit The code here is just temp sensor test stuff & very untidy, but the final code will go in the Spa & Room heating controllers. 2016-05-01_220535_Thermistor_Read.zip Cheers Phil |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 5913 |
The are many ways to do menus and it depends a lot on the flow of your main program. The one big issue with the method you are using is the PAUSE statement. This halts the full program for 5 seconds and prevents any keyboard entry. This adaption lets the program continue while the menu is displayed. You can choose to process INKEY$ input only while the menu is displayed (as in the option 9) or at any time. The menu will close with the zero key or after 5 seconds. DIM Esc AS STRING Esc = CHR$(27) DO k$ = INKEY$ SELECT CASE k$ CASE "m","M" DoMenu CASE "1" PRINT "Changing target Temperature" CASE "2" PRINT "Changing Differential" CASE "3" PRINT "Changing Solar Level" CASE "9" PRINT "Stop & Shutdown" IF menu = 1 THEN END ' only end program if menu is showing CASE "0" PRINT "Exiting" EndMenu END SELECT '. '. '. '. '. LOOP SUB DoMenu SETTICK 5000, EndMenu,4 ' set menu timeout 'Output Stuff to console for debugging purposes PRINT Esc+"[2J"; PRINT Esc+"[f"; PRINT "1. Change Target Temperature" PRINT "2. Change Differential" PRINT "3. Change Solar Level" PRINT "9. Stop & Shutdown" PRINT "0. Exit" menu = 1 ' a flag so you know when the menu is active END SUB SUB EndMenu SETTICK 0,0,4 ' disable the menu timeout PRINT Esc+"[2J"; menu = 0 ' reset menu active flag END SUB This method may not be the best for you main program flow but it may be of some use. Jim VK7JH MMedit MMBasic Help |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Sorry Jim, I should of explained in my post that the pause was just in place to test that first bit of coding I did. Just to see if my inkey$ & the menu it triggered were going to work reliably. From there I need to capture the option numbers for the menu items & then enter probably a 4 character number, ie 27.5 etc. Would I not also need some of the case statement you listed inside the DoMenu Sub? Phil. |
||||
Print this page |