Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: January 23, 2011, 04:10:59 pm
Hi

Post your code and I'll have a look

2  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: May 18, 2010, 11:32:46 pm
Sorry Scratch that it still does it smiley-sad!!!!
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: May 18, 2010, 05:40:00 pm
Hi Mowcius,

I think I found the error in your code

Code:
 if(line > 2){
  line = 2;
  prognumber++;
  [glow]}[/glow]
  if(prognumber > 4){
  prognumber = 5;
  }
[glow]//}[/glow]
  menu();
  }

I moved the } bracket from the commented out section to the other highlighted section and now I doesn't lock up.

I think what was happening is that when you press 2 button simultaneously it would make the line number = 1 and the prognumber >4 so the if statement would allow it to go though..

What do you think

Ben
4  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: May 18, 2010, 05:09:18 pm
Thanks Mowcius Look foward to your reply.

5  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: May 17, 2010, 11:39:17 pm
Hi Mowcius,

I loaded your code up & it looks great and seemed to work fine, but after about 10 - 20 key presses it just hangs.

I have the buttons wired 5v to one side if the switch and the Digital pin with a 10K resistor pulling low the other side of the switch.

any ideas????

Thanks

Ben
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: May 16, 2010, 03:03:35 am
Hi Mowcius,

thanks Im going to load it up tomorrow to see how it works.

thanks

Ben
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: May 13, 2010, 04:50:32 pm
Hi Mowcius Sorry Yes Im still reading this I have been away and haven't had a chance to come back here.

I have been playing with the first code you gave me ( 1 Button) and I have it working fully.

Do you mind having a quick look to see if there are an obvious errors/problems.

Code:
/* Menu Code by Adapated from Mowcius Code
*/

#include <NewSoftSerial.h>
#include <EEPROM.h>

NewSoftSerial LCDserial(0, 3);


// START Menu Stuff
int menuButton = 2;    
int programnumber = 1;
int menudelaycount = 0;
int menudelaycount2 = 0;
// End Menu Stuff

long ramCycle = 0;

int FRPin =  8;  
int MotorPin = 7;

long fillDelay = 1000;
long holdDelay = 500;
int ramPulse = 500;

void setup()   {  
  LCDserial.begin(9600);
  Serial.begin(9600);
  LCDclear();
  selectLineOne();
  LCDserial.print("Azzurra Bathroom");
  selectLineTwo();
  LCDserial.print("Testing Rig V1.0");
  delay(5000);
  pinMode(menuButton, INPUT);
  
  pinMode(FRPin, OUTPUT);  
  pinMode(MotorPin, OUTPUT);
  
  //Pull Ram in fully
  retractRam();
  
  mainMenu();
}

void loop(){
}


void start()                    
{
  delay(3000);
  while(digitalRead(menuButton) == LOW){
    
    LCDclear();
  
    //Turn on Motor then push out for ramPulse Time
    selectLineOne();
    LCDserial.print("Extending Ram");
    digitalWrite(MotorPin, HIGH);  
    digitalWrite(FRPin, HIGH);
    delay(ramPulse);
    checkPress();
    
    //Hold the motor for holdDelay Time (-- PUSH OUT--)
    LCDclear();
    selectLineOne();
    LCDserial.print("Holding Ram");
    digitalWrite(MotorPin, LOW);
    delay(holdDelay);
    checkPress();
    
    //Turn on Motor then pull in for ramPulse Time
    LCDclear();
    selectLineOne();
    LCDserial.print("Retracting Ram");
    digitalWrite(MotorPin, HIGH);  
    digitalWrite(FRPin, LOW);        
    delay(ramPulse);
    checkPress();
    
    //Hold the motor for holdDelay Time (--PULL IN--) & Print Current Ram Count
    LCDclear();
    selectLineOne();
    LCDserial.print("Holding Ram");
    digitalWrite(MotorPin, LOW);
    ramCycle++;
    LCDclear();
    selectLineOne();
    LCDserial.print("Ram Count   ");
    selectLineTwo();
    LCDserial.print(ramCycle);
    delay(fillDelay);
    checkPress();
    
  }
 
}

void retractRam()
{
  LCDclear();
  selectLineOne();
  LCDserial.print("Retracting Ram");
  selectLineTwo();
  LCDserial.print("to Home Position");
  digitalWrite(MotorPin, HIGH);
  digitalWrite(FRPin, LOW);
  delay(6000);
  digitalWrite(MotorPin, LOW);
}

void mainMenu()
{
 LCDclear();  //clears the LCD
 selectLineOne();
 switch (programnumber) { //reads the program number (set as 1 in setup)
 case 1:            //displays the first menu item              
   LCDserial.print("Set Fill Delay");
   break;
 case 2:        //displays the second menu item
   LCDserial.print("Hold Delay");
   break;
 case 3:       //displays the third menu item
   LCDserial.print("Ram Pulse");
   break;
 case 4:            //displays the first menu item              
   LCDserial.print("Start");
   break;
 case 5:       //displays the third menu item
   LCDserial.print("Stop");
   break;
 default:      //if errors then it goes to default item
   LCDserial.print("Fill Delay");
}
 selectLineTwo();
 LCDserial.print("Next >");    //next code in specific position
 while(digitalRead(menuButton) == HIGH){} //while button is high do nothing: {} (helps with debounce after button has been pressed)
 delay(5);
 while(digitalRead(menuButton) == LOW){} //wait until button has been pressed (taken high).
   menudelaycount = 0; //clear menu delay
   while(menudelaycount <500){ //do this code within the 500 limit (over 500ms because of other stuff that is done and takes time)
   delay(1);
   menudelaycount++;
   if(digitalRead(menuButton) == LOW){ //if the button goes low (button released) within this loop then it advances one menu option
     programnumber++; //increase the menu option
   if(programnumber > 5){
     programnumber = 1;
   }
   mainMenu(); //then run menu code from start: the change in program number makes it change the option it is on.
   }
 }
 switch (programnumber) { //if the button is not let go within the menu time stated above then it does not loop back and then selects the subroutine from this switch case:
     case 1:
       //LCDserial.print("Fill Func");
       fillMenu();
       break;
     case 2:
       // LCDserial.print("Delay Func");
        delayMenu();
       break;
     case 3:
        //LCDserial.print("Pulse Func");
        pulseMenu();
       break;
      case 4:
        LCDclear();
        selectLineOne
        LCDserial.print("Starting Test");
        start();
       break;
     case 5:
        LCDserial.print("Stop Func");
       break;
     default:
        LCDserial.print("Default Start Func");
     }
}

void fillMenu()
{
   LCDclear();
   selectLineOne();
   LCDserial.print(fillDelay);
   selectLineTwo();
   LCDserial.print("Next >");    
  
   while(digitalRead(menuButton) == HIGH){}
     delay(5);
   while(digitalRead(menuButton) == LOW){}
     menudelaycount = 0;
   while(menudelaycount <500){
     delay(1);
     menudelaycount++;
     if(digitalRead(menuButton) == LOW){
        fillDelay = fillDelay +3000;
     if(fillDelay > 120000){
       fillDelay = 0;
     }
   fillMenu();
   }
 }
   LCDclear();
   selectLineOne();
   LCDserial.print("Fill Delay set @ ");
   selectLineTwo();
   LCDserial.print(fillDelay);
   delay(3000);
   mainMenu();
}

void delayMenu()
{
  LCDclear();
  selectLineOne();
  LCDserial.print(holdDelay);
  selectLineTwo();
  LCDserial.print("Next >");    
  
   while(digitalRead(menuButton) == HIGH){}
     delay(5);
   while(digitalRead(menuButton) == LOW){}
     menudelaycount = 0;
   while(menudelaycount <500){
     delay(1);
     menudelaycount++;
     if(digitalRead(menuButton) == LOW){
        holdDelay = holdDelay +500;
     if(holdDelay > 60000){
       holdDelay = 0;
     }
   delayMenu();
   }
 }
   LCDclear();
   selectLineOne();
   LCDserial.print("Hold Delay set @ ");
   selectLineTwo();
   LCDserial.print(holdDelay);
   delay(3000);
   mainMenu();
}

void pulseMenu()
{
   LCDclear();
   selectLineOne();  
   LCDserial.print(ramPulse);
   selectLineTwo();
   LCDserial.print("Next >");    
  
   while(digitalRead(menuButton) == HIGH){}
     delay(5);
   while(digitalRead(menuButton) == LOW){}
     menudelaycount = 0;
   while(menudelaycount <500){
     delay(1);
     menudelaycount++;
     if(digitalRead(menuButton) == LOW){
        ramPulse = ramPulse +250;
     if(ramPulse > 6000){
       ramPulse = 0;
     }
   pulseMenu();
   }
 }
   LCDclear();
   selectLineOne();
   LCDserial.print("Ram Pulse set @ ");
   selectLineTwo();
   LCDserial.print(ramPulse);
   delay(3000);
   mainMenu();
}

void checkPress()
{
  if (digitalRead(menuButton) == HIGH)
  {
    retractRam();
    LCDclear();
    selectLineOne();
    LCDserial.print("Paused");
  //  selectLineTwo();
   // LCDserial.print("Press button to goto menu");    
    delay(500);
    while(digitalRead(menuButton) == LOW){}
    mainMenu();
    
  }
}

void selectLineOne(){  //puts the cursor at line 0 char 0.
  LCDserial.print(0xFE, BYTE);   //command flag
  LCDserial.print(128, BYTE);    //position
}

void selectLineTwo(){  //puts the cursor at line 2 char 0.
  LCDserial.print(0xFE, BYTE);   //command flag
  LCDserial.print(192, BYTE);    //position
}

void LCDclear(){
  LCDserial.print(0xFE, BYTE);   //command flag
  LCDserial.print(0x01, BYTE);   //clear command
  }

Thanks again

Ben
8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: May 11, 2010, 07:06:09 am
Hi Mowcius

That would be GREAT!!!!

I just want to thank you for all your help.  I will have my LCD tommorrow too!!

thanks

ben
9  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: May 11, 2010, 04:02:12 am
thanks
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: May 10, 2010, 11:05:55 pm
Thank Mowcius!!

I have apadapted your code into my program and the mainmenu() sub is working.

I am having problems with the fillMenu() sub.  Once I pick a delay time
it types the serial command the same amount of time (code highlighted below)

Code:
void mainMenu()
{
 //LCDclear();  //clears the LCD
// Serial.println("Program Menu"); //prints to the lcd on first line -------------------------------------------------------------------------------------------> NOT NEEDED???
// LCDsecond(); //prints to lcd on second line etc... -------------------------------------------------------------------------------------------> NOT NEEDED???
 switch (programnumber) { //reads the program number (set as 1 in setup)
 case 1:            //displays the first menu item              
   Serial.println("Set Fill Delay");
   break;
 case 2:        //displays the second menu item
   Serial.println("Reset Fill Delay");
   break;
 case 3:       //displays the third menu item
   Serial.println("Ram Pulse");
   break;
 case 4:            //displays the first menu item              
   Serial.println("Start");
   break;
 case 5:        //displays the second menu item
   Serial.println("Pause");  
   break;
 case 6:       //displays the third menu item
   Serial.println("Stop");
   break;
 default:      //if errors then it goes to default item
   Serial.println("Fill Delay");
}

 //Serial.println(0xFE, BYTE); //Command code-------------------------------------------------------------------------------------------> NOT NEEDED???
 //Serial.println(226, BYTE);  //Goes to specific point to display code-------------------------------------------------------------------------------------------> NOT NEEDED???
 Serial.println("Next >");    //next code in specific position
 while(digitalRead(menuButton) == HIGH){} //while button is high do nothing: {} (helps with debounce after button has been pressed)
 delay(5);
 while(digitalRead(menuButton) == LOW){} //wait until button has been pressed (taken high).
   menudelaycount = 0; //clear menu delay
   while(menudelaycount <500){ //do this code within the 500 limit (over 500ms because of other stuff that is done and takes time)
   delay(1);
   menudelaycount++;
   if(digitalRead(menuButton) == LOW){ //if the button goes low (button released) within this loop then it advances one menu option
     programnumber++; //increase the menu option
   if(programnumber > 6){
     programnumber = 1;
   }
   mainMenu(); //then run menu code from start: the change in program number makes it change the option it is on.
   }
 }
 switch (programnumber) { //if the button is not let go within the menu time stated above then it does not loop back and then selects the subroutine from this switch case:
     case 1:
       Serial.println("Fill Func");
       fillMenu();
       break;
     case 2:
        Serial.println("Delay Func");
       break;
     case 3:
        Serial.println("Pulse Func");
       break;
      case 4:
        Serial.println("Start Func");
       break;
     case 5:
        Serial.println("Pause Func");
       break;
     case 6:
        Serial.println("Stop Func");
       break;
     default:
        Serial.println("Default Race");
     }
}

void fillMenu()
{
   FillDelay = FillDelay +3000;
   Serial.println(FillDelay);
  
   Serial.println("Next >");    
   while(digitalRead(menuButton) == HIGH){}
     delay(5);
   while(digitalRead(menuButton) == LOW){}
     menudelaycount = 0;
   while(menudelaycount <500){
   delay(1);
   menudelaycount++;
   if(digitalRead(menuButton) == LOW){
     //programnumber++;
   if(FillDelay > 120000){
     FillDelay = 0;
   }
   fillMenu();
  }
 }
   [glow]Serial.print("Fill Delay set @ ");
   Serial.print(FillDelay);[/glow]
}

Here is my Serial Output (I dont yet have my LCD some Im using Serial insted)

Set Fill Delay
Next >
Fill Func
4000
Next >
7000
Next >
Fill Delay set @ 7000Fill Delay set @ 7000Extending Ram
Holding Ram
Retracting Ram
Holding Ram


as you can see above I pressed the button twice and it prints the serial string twice. If i press the button 3 times it prints the serial string 3 times......

thanks again for all your help

Ben

11  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: May 10, 2010, 05:30:47 am
Hi Mowcius,

Thanks for your help there are a few things I need to clarify.

I like the way you use 1 button!! but when you press the button does it go LOW?

I dont understand how to call this code??

In psuedo code

Code:
has button been pressed
   if yes
     menu();
   else
      return();

that would work ok in the loop but how does this work from setup().

Do you just continually loop until its completed??

Sorry if this sounds stupid I just cant get my head around it :-[

and finally  ;D where in my code posted above do i call to see if a button has been pressed??

thanks again
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: Menu Driven Program on: May 10, 2010, 01:12:01 am
Thanks for the tips   smiley-grin

the problem Im having is not really anything to do with the lcd its more of the button press detection.

Sorry I should have explained this better!!

I have 3 buttons <Back, >Foward & OK buttons


I need to know the correct way of detecting button press's  for 3 buttons(currenty Im using the arduino example way) and when to poll them and not cause any interferance  to the loop part of the code.

thanks

Ben
13  Forum 2005-2010 (read only) / Syntax & Programs / Menu Driven Program on: May 10, 2010, 12:25:06 am
Hi

Im in the process of building and automatic toilet cistern valve tester.

It basically consists of a linear actuator, LCD, and a couple of switches.

I am stuck trying to implement the sceen. The menu will have 6 options which have to be set before the actuator starts testing.

Menu Below

1. Fill Delay Time
2. Ram Delay Time
3. Ram Pulse Time
4. Start
5. Pause
6. Stop

obviously the pause and stop commands will have to run during the void loop() part of the code and opt 1, 2 & 3 could run in the void setup() part of the code. The pause function will have to not interupt the current ram cycle.

Below is my current code with static variables for opt 1,2 3.

Code:
int FRPin =  8;  
int MotorPin = 7;

int FillDelay = 10000;
int RamDelay = 500;
int RamPulse = 2000;
int TCount;
int Cycles = 10;

void setup()   {  
  Serial.begin(9600);
  Serial.println("Testing Rig V1.0");
  Serial.println("");
  
  pinMode(FRPin, OUTPUT);  
  pinMode(MotorPin, OUTPUT);
  
  //Pull Ram in fully
  Serial.println("Retracting Ram");
  digitalWrite(MotorPin, HIGH);
  digitalWrite(FRPin, LOW);
  delay(6000);
  digitalWrite(MotorPin, LOW);
}


void loop()                    
{
  for(int i=0; i<Cycles; i++){
    
    
    //Turn on Motor then push out for RamPulse Time
    Serial.println("Extending Ram");
    digitalWrite(MotorPin, HIGH);  
    digitalWrite(FRPin, HIGH);
    delay(RamPulse);
    
    //Hold the motor for RamDelay Time (-- PUSH OUT--)
    Serial.println("Holding Ram");
    digitalWrite(MotorPin, LOW);
    delay(RamDelay);
    
    //Turn on Motor then pull in for RamPulse Time
     Serial.println("Retracting Ram");
    digitalWrite(MotorPin, HIGH);  
    digitalWrite(FRPin, LOW);        
    delay(RamPulse);
    
    //Hold the motor for RamDelay Time (--PULL IN--)
    Serial.println("Holding Ram");
    Serial.println("");
    digitalWrite(MotorPin, LOW);
    delay(FillDelay);
    
    //test code
    TCount++;
    Serial.println(TCount);
  }
}

The LCD im using is a sparkfun Serial Enabled 16x2 LCD - Black on Green 5V.

Any help on how to impletmen this would be great.

thanks ben
14  Forum 2005-2010 (read only) / Syntax & Programs / Re: Scrolling menu program hangs... on: May 21, 2010, 09:09:17 pm
Hi Mowcius & bhagman,

I would like to thank you both for all your help especially Mowcius!!  and thanks to everyone else who contributed.

I love this community. ;D


thanks all

ben
15  Forum 2005-2010 (read only) / Syntax & Programs / Re: Scrolling menu program hangs... on: May 20, 2010, 05:44:52 am
oops fixed
Pages: [1] 2