Display + Button
PlaneTeeR
Posts: 100
Hello everyone,
I now have a LCD display and button, all is working. But now I have to make a selection with the button what I want to display. The LCD has two lines, the upper always shows the speed, and the lower shows 3 things nl: AVG(Average Speed), DST (Distance)·& CHR (Chronometer). How do I make this without much programm to run. I thought of something like this:
int button; //the state of the button
if(CPU.readPin(BT1PIN) == false){
· button++;}
··if(button>2){
····button=0;}
And then selecting with another if else statement which info you want to diplay, is this a good idea, or can it be faster?
Thanks Johnny
·
I now have a LCD display and button, all is working. But now I have to make a selection with the button what I want to display. The LCD has two lines, the upper always shows the speed, and the lower shows 3 things nl: AVG(Average Speed), DST (Distance)·& CHR (Chronometer). How do I make this without much programm to run. I thought of something like this:
int button; //the state of the button
if(CPU.readPin(BT1PIN) == false){
· button++;}
··if(button>2){
····button=0;}
And then selecting with another if else statement which info you want to diplay, is this a good idea, or can it be faster?
Thanks Johnny
·
Comments
if (!CPU.readPin(BT1PIN)) {
· button = (button+1)%3; //result values 0, 1 and 2
}
If the code that follows the above takes a bit of time I see no problems.
But there is also a Button class that allows you to debounce, but it
probably is not required.
regards peter
You have followed my project and I've noticed that, when the speed is formatted and distance or something else on line 2, the javelin mc will not read below 70ms between pulses. When I let out these codes it reads to 1 ms. Is there a way to seperate these two things, so it wil run on the background and the display wil update itself every second or so?
Johnny
That already saves alot of time. You can use another timer for your display update
section:
static Timer lcdTimer = new Timer();
with your lcd update code
···· if (lcdTimer.timeout(1000)) { //update lcd approx. once per second
······· //your lcd update code
······· lcdTimer.mark();
···· }
That leaves you more time to check pulses and update speed,·distance and time variables.
regards peter
...output omitted...
while (!CPU.readPin(senPin));
while (true) {
while (CPU.readPin(senPin));
tPulse.mark();
CPU.writePin(ledPin,true);
while (!CPU.readPin(senPin));
...output omitted...
When i put it inside these loops it does not·work until i hold the button and there comes a pulse! How should i do this?
Johnny
Post Edited (PlaneTeeR) : 5/26/2006 6:30:44 PM GMT
That way the button is scanned once every mainloop.
You mentioned the mainlooptime varied from 10-50 mSec or so,
which is sufficient.
regards peter
For a fast response to the button press,
insert a button test within each while loop.
Then check the button test result outside the while loops.
See attachment. I set the button to pin13.
(buttonpin=low is button pressed, so a pullup resistor is required)
regards peter
low speeds 30 Km/h > press a bit longer than normal
middle speed 30 -·70 Km/h > press·normal stable button
fast·70 Km/h or higher > button very unstable, when pressed you can skip a few modes.
With this i can live.
Also I have all these display format formules in the loop, so when the bike stops i can't get any readings from it. Or i have to place them also outside but that is too much of the good i think. Or can this all be solved with different classes, one class display one processor and so? Can this be done with javelin? So that i create objects where the pulses are constant read and so on?
Johnny
the button, the pulse while loops are exited immediately and you then
enter the button code. No matter if a pulse is being detected, once the
button is pressed, the current pulse simply is missed. That is no
problem as long as you calculate distance using·looptime.
To make the button·more stable at higher speeds,
wait for the button release,
Add the following to your button code
CPU.delay(525); //wait 50 mSec (debounce)
while (!CPU.readPin(buttonPin) ; //wait for button release
CPU.delay(525); //wait 50 mSec (debounce, optional)
This makes sure you have a valid button press.
Since there is no validPulse if the button has been pressed
the delay·is not a problem.
regards peter