Page 1 of 1

Increase/Decrease a variable Value on a press of a button

Posted: Sat Nov 23, 2019 2:53 pm
by Derrihj
Hi guys am happy to ask as many questions as i can and get as much info as i can so that in future i can write my projects with no more questions asked.Thanks to all of you guys that help me out.My next question is, how do we increase and decrease a variable with one button to increase it when pressed and the other button to deccrease the same variable when pressed? For example after reading the temperature and one may need to set a fixed value as Temp reference then one would use two buttons to increase or decrease values of "Temp ref" to a required value.I dont want to use a keypad for this simple job but would love to learn how to use two buttons.Thanks guys,you can help by witting a simple flow chat just to show the part of the two buttons in action.

Re: Increase/Decrease a variable Value on a press of a button

Posted: Sat Nov 23, 2019 4:26 pm
by medelec35
Hi Derrihj ,
Attached is a simple way of setting temperature Reference variable between 5 and 30.

Re: Increase/Decrease a variable Value on a press of a button

Posted: Sat Nov 23, 2019 11:03 pm
by Derrihj
Hi Medelec35 and thanks for your quick response,ive added an LCD in your flow-chat so that i could see what is going on but the result i got is not exactly what am looking for yours goes from 30 t0 10 the goes to something like 70. But what i want is for temp ref to be adjustable from 0 to 30 and back from 30 to 0.Have a look at the flowchat with the LCD attached here. Thanks once again sir.

Re: Increase/Decrease a variable Value on a press of a button

Posted: Sat Nov 23, 2019 11:17 pm
by mnf
When the temp goes from >= 10 to below 10 the second digit isn't cleared on the display.

So 10 -> 9 will display 90 which looks incorrect...

Martin

Re: Increase/Decrease a variable Value on a press of a button

Posted: Sat Nov 23, 2019 11:51 pm
by medelec35
Hi Derrihj,
Marin is correct in what he says.
I have modified your flowchart and removed the string as its not required

Re: Increase/Decrease a variable Value on a press of a button

Posted: Sun Nov 24, 2019 12:10 am
by Derrihj
Ok thanks Martin for that correction I edited it and i think now its working

Re: Increase/Decrease a variable Value on a press of a button

Posted: Sun Nov 24, 2019 12:27 am
by medelec35
Derrihj wrote: I edited it and i think now its working
Ok that's great, but your flowchart with additional string works the same as mine with the string removed,
As long as you are happy, that's the main thing.

Re: Increase/Decrease a variable Value on a press of a button

Posted: Sun Nov 24, 2019 12:32 am
by Derrihj
Yes Medelec35 thanks for your work it has been so helpfull, ive seen yours and it works just the same as mine but correct me if am wrong coz one time i used the print Number comand and it had trouble printing Floating point numbers thats why i decided to use strings through out.

Re: Increase/Decrease a variable Value on a press of a button

Posted: Sun Nov 24, 2019 12:54 am
by medelec35
Hi Derrihj,
Mine is not printing floating point, its printing bytes (0 to 255).
If you have a floating point, you can convert it to string (FloatToString function), then print string.