I am trying to pass a variable "Breakfast" into a function, change the variable and output it as "Time" the variable Breakfast is passed into "Menu Two" and within that I analyze a button state and assign a number to "Breakfast"
I cannot change the value of "Time" or "Breakfast" I checked the button, it works fine and is normally high. I checked everything else but I cannot output "Breakfast" by returning the variable.
Please help!!!
Thanks
Bill
Code is attached
Firmware_Rev3_pde.pde (10.3 KB)
Breakfast = 98999990;
That's too big to go into an "int".
Breakfast = 48885;
So's that.
Lots of code.
Not many comments.
You got a long way before discovering the flaw in your design.
Where is the earlier trial code?
Do you see a pattern here that could save you a lot of typing (and memory)?
void MenuThree(int OzMenu){
switch (OzMenu) {
case 1:
lcd.setCursor(0, 1);
lcd.print("Dispense 1 oz ");
break;
case 2:
lcd.setCursor(0, 1);
lcd.print("Dispense 2 oz ");
break;
case 3:
lcd.setCursor(0, 1);
lcd.print("Dispense 3 oz ");
break;
case 4:
lcd.setCursor(0, 1);
lcd.print("Dispense 4 oz ");
break;
case 5:
lcd.setCursor(0, 1);
lcd.print("Dispense 5 oz ");
break;
case 6:
lcd.setCursor(0, 1);
lcd.print("Dispense 6 oz ");
break;
case 7:
lcd.setCursor(0, 1);
lcd.print("Dispense 7 oz ");
break;
case 8:
lcd.setCursor(0, 1);
lcd.print("Dispense 8 oz ");
break;
case 9:
lcd.setCursor(0, 1);
lcd.print("Dispense 9 oz ");
break;
case 10:
lcd.setCursor(0, 1);
lcd.print("Dispense 10 oz ");
break;
case 11:
lcd.setCursor(0, 1);
lcd.print("Dispense 11 oz ");
break;
case 12:
lcd.setCursor(0, 1);
lcd.print("Dispense 12 oz ");
break;
default:
lcd.setCursor(0, 1);
lcd.print("Error");
}
}
Pretty much the same for MenuTwo too.
I'm Still pretty new to this. Trying to stumble my way through it. Any suggestions would be greatly appreciated as I am probably embarrassing myself in front of good programmers.
Thanks
Clue: something like this.
lcd.setCursor ( 0, 1 );
if ( OzMenu < 1 || OzMenu > 12 ) lcd.print ( "Error" );
else
{
lcd.print ( "Dispense " );
lcd.print ( OzMenu, DEC ); // I think I have this form right, but not sure
lcd.print ( "oz " );
}
I don't know if it would be faster/smaller to use sprintf ( ) to format the output string and make one call to lcd.print.
Well for starters as AWOL said look at the menu functions, I can't see why the following wouldn't do the same.
void MenuThree(int OzMenu){
lcd.setCursor(0, 1);
lcd.print("Dispense ");
lcd.print(OzMenu);
lcd.print(" oz ");
}
I'm not familiar with the LCD library so the print format may not be exactly right, but that's the idea.
You could also set the cursor to the end of "Dispense " and not print that every time.
pass a variable "Breakfast" into a function, change the variable and output it as "Time"
I'm not sure exactly what you mean here but if Breakfast and Time are global variables then they can be read/written from anywhere in your code.
People tend to frown on the use of globals but for the average Arduino sketch I see no reason not to just use that technique. In which case you don't need to "pass" the variable to a function at all.
I see you already have them as globals so is there a particular reason you need to pass Breakfast to a function?
Rob
Thank you all very much I will try those tips. I am doing this for a design project and am not very strong in programming. It's for an Ethernet enabled programmable dog feeder. The Ethernet code is being developed by another team member. I am struggling with the timing and the function creation. I constantly write functions but appear to have trouble getting them to work.
I am going to attempt your code examples and will post an updated code tomorrow.
Thanks again
Bill