I've looked, scratched my head and referenced but can't find the answer which I'm sure is easy (please be gentle with me!):
I am trying to increment a value when a button is pressed. buttonPress () returns a String value of: Left, Right, Up, Down, Accept or Reject and the below code quite happily increases or decreases the pulseCount variable and displays it as appropriate. I am struggling to break out of the While loop when Accept or Reject is pressed, Serial Monitor shows the correct string is being passed from buttonPress (). This means that my function wont break out once I have set number I need and changing the While has indicated that this is the halt.
Syntax/Capability escapes me here, any gentle pointers would be greatly appreciated Code section below.
clearScreen ();
lcd.print("Setup Menu - Active");
lcd.setCursor(0, 2);
lcd.print("Pulse Count: ");
lcd.setCursor(13, 2);
lcd.print(pulseCount);
do
{
increment(pulseCount,1);
lcd.setCursor(13, 2);
lcd.print(pulseCount);
Serial.print(button); //Debug Code
}
while (button != "Accept" || button != "Reject");
if (button == "Reject")
{
menuSetup1();
}
lcd.setCursor(0,3);
lcd.print("Trigger Set to: ");
lcd.setCursor(16,3);
lcd.print(pulseCount);
buttonPress ();
if (button == "Reject"){menuTop();}
}
int increment (int startValue, int value){
buttonPress ();
if (button == "Up")
{
pulseCount = pulseCount + value;
}
else if(button =="Down")
{
pulseCount = pulseCount - value;
}
else{
return pulseCount;
}
}
Apologies for not putting the entire code in, I was not able to as it's larger than 9500 characters and therefore wont post =( In future, do I need to break the code down into more than one post to get it onto the forum?
In future, do I need to break the code down into more than one post to get it onto the forum?
No. Just below the text window, there is a link called Additional Options... Select that, and one of the things you can do is attach one or more files that are larger than the 9500 character limit.
Even better, though, is to create a smaller sketch that illustrates the problem.
Looking at his posted project he's going to need a little, OK a LOT, more help then my simple posting provides.
The Arduino 1.x (and presumably later) 'String' class ought to be taken out back and buried. It's constantly being used and abused by those who don't know any better.
400greyBike:
Syntax/Capability escapes me here, any gentle pointers would be greatly appreciated Code section below.
If the button is being specified elsewhere in your code then return it as an enumerated value instead of as a string or String. Then you can use a plain old numeric comparison (or use it in switch cases etc) without having to do string comparisons everywhere.
Many thanks for the pointers, I'll return the necessary values without using String and continue on.
It's difficult to know everything you need to when you've only done the Kit Exercises and then started off on a project that will motivate enough to continue. You learn from your mistakes, us newbies simply can't accrue all the necessary knowledge up-front, and trawling through the forum and internet doesn't always answer a question that you're not really sure you've identified yet.
Rather than hang my hat up (I'm feeling a bit demotivated now), I'll soldier on and see if I can get the HW to do what it's intended to do, this ultimately being the goal. I'll learn how to tidy and streamline the code as I go (with a LOT of help) but will try and have a better picture of the issue before asking a question.