Go Down

Topic: MENWIZ: yet another character lcd menu wizard library (Read 98669 times) previous topic - next topic

GnFlala

#525
May 04, 2015, 06:59 pm Last Edit: May 04, 2015, 07:18 pm by GnFlala
After several  tries , i had cut the settings in 2 sub menus Settings 1 et Settings 2 .

My new code is :
Code: [Select]
//MENWIZ EXAMPLE
#include <Wire.h>
//INSERT ALL THE FOLLOWING 5 INCLUDES AFTER INCLUDING WIRE LIB
//#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <buttons.h>
#include <MENWIZ.h>
#include <EEPROM.h>    // to be included only if defined EEPROM_SUPPORT

// DEFINE ARDUINO PINS FOR THE NAVIGATION BUTTONS
#define UP_BUTTON_PIN       6
#define DOWN_BUTTON_PIN     A1//7
#define CONFIRM_BUTTON_PIN  A0//9
#define ESCAPE_BUTTON_PIN   8

//Create global object menu and lcd
menwiz menu;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity

/* Valeurs par defaut dans EEprom */
int centerposServo1 = 1500;      //mode1 (in address 1)
int centerposServo2 = 1500;      //mode2 (in address 2)
int idelposServos1 = 1200;//600       //mode3 (in address 3)
int idelposServos2 = 1200;//600       //mode3 (in address 3)
int responseTime = 2;                      //mode4 (= a TAUX_DE_MOYENNAGE) (in address 4)
int fullThrottle = 2000;//2400        //mode5 (in address 5)
int beginSynchro = 1200;//            //mode5 (in address 6)
int auxChannel = 1;                        //mode6 (in address 7)
int reverseServo1 = 0;                     //mode7 (in address 8)
int reverseServo2 = 0;                     //mode7 (in address 9)
int minimumPulse_US = 1000;
int maximumPulse_US = 2000;
int telemetryType = 0 ;                    //0- Rien, 1- FrSky (S-Port), 2- Futaba Sbus, 3- Hitec, 4- Hott, 5- Jeti 6- Spektrum
int moduleMasterOrSlave = 0;               //0 = module maitre , 1= module esclave
int nbPales = 2; // the number of blades of the propeller or nb of magnets

void setup(){
  _menu *r,*s1,*s2,*s3;
  _var *v;
  int  mem;

  Serial.begin(19200); 
 
  // have a look on memory before menu creation
  Serial.println(sizeof(menwiz));
  mem=menu.freeRam();
  menu.getErrorMessage(true);
  menu.begin(&lcd,20,4);
  //menu.setBehaviour(MW_MENU_INDEX,false);   

  //create the menu tree
  r=menu.addMenu(MW_ROOT,NULL,F("Main menu"));              //create a root menu at first (required)
    s1=menu.addMenu(MW_SUBMENU,r,F("Settings 1"));          //add a child (submenu 1) node to the root menu
//    s1->setBehaviour(MW_MENU_COLLAPSED,true);         

      s2=menu.addMenu(MW_VAR,s1,F("Center Servo 1"));       //mode1
          s2->addVar(MW_AUTO_INT,&centerposServo1,minimumPulse_US,maximumPulse_US,5);
      s2=menu.addMenu(MW_VAR,s1,F("Center Servo 2"));       //mode2
          s2->addVar(MW_AUTO_INT,&centerposServo2,minimumPulse_US,maximumPulse_US,5);
      s2=menu.addMenu(MW_VAR,s1,F("Idle Position 1&2"));    //mode3
          s2->addVar(MW_AUTO_INT,&idelposServos1,minimumPulse_US,maximumPulse_US,5);
      s2=menu.addMenu(MW_VAR,s1,F("Response time"));        //mode4
          s2->addVar(MW_AUTO_INT,&responseTime,0,4,1);     
      s2=menu.addMenu(MW_VAR,s1,F("Full throttle"));        //mode5
          s2->addVar(MW_AUTO_INT,&fullThrottle,minimumPulse_US,maximumPulse_US,5); 
      s2=menu.addMenu(MW_VAR,s1,F("Begin synchro"));        //mode5
          s2->addVar(MW_AUTO_INT,&beginSynchro,minimumPulse_US,maximumPulse_US,5);
      s2=menu.addMenu(MW_VAR,s1,F("Min general"));          //mode5
          s2->addVar(MW_AUTO_INT,&minimumPulse_US,600,2200,5);
      s2=menu.addMenu(MW_VAR,s1,F("Max general"));          //mode5
          s2->addVar(MW_AUTO_INT,&maximumPulse_US,600,2200,5);
         
    s1=menu.addMenu(MW_SUBMENU,r,F("Settings 2"));          //add a child (submenu 2) node to the root menu
      s3=menu.addMenu(MW_VAR,s1,F("Auxiliary chanel"));     //mode6
          s3->addVar(MW_AUTO_INT,&auxChannel,1,6,1);
      s3=menu.addMenu(MW_VAR,s1,F("Nb of blades"));         //mode6
          s3->addVar(MW_AUTO_INT,&nbPales,1,5,1);         
      s3=menu.addMenu(MW_VAR,s1,F("Telemetry"));            //mode6
          s3->addVar(MW_AUTO_INT,&telemetryType,0,6,1);       
      s3=menu.addMenu(MW_VAR,s1,F("Reverse servo 1"));      //mode7
          s3->addVar(MW_AUTO_INT,&reverseServo1,0,1,1);
      s3=menu.addMenu(MW_VAR,s1,F("Reverse servo 2"));      //mode7
          s3->addVar(MW_AUTO_INT,&reverseServo2,0,1,1);
         
//    /* other main menu options */
//    s1=menu.addMenu(MW_VAR,r,F("Elapsed Time"));           //add a terminal node (that is "variable") create an "action" associated to the terminal node...
//      s1->addVar(MW_ACTION,elapsedTime);
//      s1->setBehaviour(MW_ACTION_CONFIRM,false);     
//    s1=menu.addMenu(MW_VAR,r,F("Save to EEPROM"));           //add a terminal node (that is "variable") create an "action" associated to the terminal node...
//      s1->addVar(MW_ACTION,savevar);                     //the act function as default will be called when enter button is pushed
//
//    s1=menu.addMenu(MW_VAR,r,F("Load to EEPROM"));        //add a terminal node (that is "variable") create an "action" associated to the terminal node...
//      s1->addVar(MW_ACTION,loadvar);                     //the act function as default will be called when enter button is pushed
//                   
//    s1=menu.addMenu(MW_VAR,r,F("Write to Serial"));       //add a terminal node (that is "variable") create an "action" associated to the terminal node...
//      s1->addVar(MW_ACTION,act);                         //the act function as default will be called when enter button is pushed
////      s1->setBehaviour(MW_ACTION_CONFIRM,false);         //...if you don't need action confirmation

  //declare navigation buttons (required)
  menu.navButtons(UP_BUTTON_PIN,DOWN_BUTTON_PIN,ESCAPE_BUTTON_PIN,CONFIRM_BUTTON_PIN);

  //(optional)create a user define screen callback to activate after 10 secs (10.000 millis) since last button push
  menu.addUsrScreen(mode0,10000);

  //(optional) create a splash screen (duration 5.000 millis)with some usefull infos the character \n marks end of LCD line
  //(tip): use preallocated internal menu.sbuf buffer to save memory space!
//  sprintf(menu.sbuf,"MENWIZ TEST V %s\n.Free mem. :%d\n.Used mem  :%d\n.Lap secs  :%d",menu.getVer(),menu.freeRam(),mem-menu.freeRam(),5);
//  menu.addSplash((char *) menu.sbuf, 5000);
  }

void loop(){
  menu.draw();

  }

void mode0(){
  //MAIN APPLICATION CODE
}

// user defined callbacks
// WARNING avoid sprintf usage: it requires > 1.5 kbytes of memory!
void elapsedTime(){
//  static  char buf[7];
//  strcpy(menu.sbuf,"User screen"); //1st lcd line
//  strcat(menu.sbuf,"\nUptime (s): ");strcat(menu.sbuf,itoa((int)(millis()/1000),buf,10));//2nd lcd line
//  strcat(menu.sbuf,"\nFree mem  : ");strcat(menu.sbuf,itoa((int)menu.freeRam(),buf,10));//3rd lcd line
//  strcat(menu.sbuf,"\n"); //4th lcd line (empty)
//  menu.drawUsrScreen(menu.sbuf);
//  delay(5000);
}
 
void act(){
  //Serial.println("FIRED ACTION!");
 }
 
void savevar(){
  menu.writeEeprom();
  }
 
void loadvar(){
  menu.readEeprom();
  }


I am always limited by the memory, i think. (tested on Uno) !

I have also a curious issue with the lines that follow:
Code: [Select]
      s3=menu.addMenu(MW_VAR,s1,F("Auxiliary chanel"));     //mode6
          s3->addVar(MW_AUTO_INT,&auxChannel,1,6,1);
      s3=menu.addMenu(MW_VAR,s1,F("Nb of blades"));         //mode6
          s3->addVar(MW_AUTO_INT,&nbPales,1,5,1);         
      s3=menu.addMenu(MW_VAR,s1,F("Telemetry"));            //mode6
          s3->addVar(MW_AUTO_INT,&telemetryType,0,6,1);       
      s3=menu.addMenu(MW_VAR,s1,F("Reverse servo 1"));      //mode7
          s3->addVar(MW_AUTO_INT,&reverseServo1,0,1,1);
      s3=menu.addMenu(MW_VAR,s1,F("Reverse servo 2"));      //mode7
          s3->addVar(MW_AUTO_INT,&reverseServo2,0,1,1);


I can't update the variables !

For my test , i use only two buttons on A0 et A1 (UP and CONFIRM)
i see in your code this

Code: [Select]
int minimumPulse_US = 1000;

later you use this int in a menu item

 
Code: [Select]
    s2=menu.addMenu(MW_VAR,s1,F("Begin synchro"));        //mode5
         s2->addVar(MW_AUTO_INT,&beginSynchro,minimumPulse_US,maximumPulse_US,5);
     s2=menu.addMenu(MW_VAR,s1,F("Min general"));          //mode5
         s2->addVar(MW_AUTO_INT,&minimumPulse_US,600,2200,5);


Can you please tell me if you change the Min general (nt minimumPulse_US) from within menwiz from 1000 to something else if the begin synchro has the new value as a minimum number?
Or begin synchro always reads 1000 as minimum number?

Thanks in advance.



pierrotm777

minimumPulse_US is a value that can be equal from 600 to 1000 µs.
maximumPulse_US is a value that can be equal from 2000 to 2200 µs.

So beginSynchrocan to be equal from 600 to 2200 µs.

razvan983

#527
May 17, 2015, 05:07 pm Last Edit: May 17, 2015, 05:08 pm by razvan983
Hi everybody.I need hellp with my stove controller( my knowledge in programing is zero).I want an opinion if I must change something of my code  that is made only with copy and paste.And what y must to put in the histeris(I want to have a delay of tempC  0-10 ).Sorry for my English.This is my code:

pierrotm777

May be can you change
static  char buf[7];
by
static  char buf20];

Because your LCD has 20 columns !

razvan983

Ok thanks a lot.I will change the number and I need help with Histeresis menu I want to set the tempC- ds 1820- delay(0-10 C).Thanks.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy