Using a button, LCD, user interface code
I'm trying to display some instructions on my serial LCD, and have them displayed and repated over and over until the user presses a pushbutton switch. I would like each message to be displayed for roughly 2 or 3 seconds (enough time to read) before the next message is displayed, however I would like my program to respond instantly when the pushbutton is pressed. In otherwords, I want my javelin to constantly check the switch's state and respond immediately to any change.
The twist is that the javelin is actually getting the switch data from my BS2 through a Uart. I would like some ideas on how to best implement this user interface so that it is quick and responsive. Here is what I have been considering:
For **wait period** I was thinking of:
however, the "break" breaks away from the IF statement, not the main while loop. I hope this makes sense.
So I'm just trying to implement a simple, user friendly quick responding interface but it is turning out to be pretty complicated. This is my first time doing something like this, any input on how to best implement this would be greatly appreciated, thanks.
The twist is that the javelin is actually getting the switch data from my BS2 through a Uart. I would like some ideas on how to best implement this user interface so that it is quick and responsive. Here is what I have been considering:
while(true) { LCD.write("message 1") **wait period** LCD.write("message 2") *wait period** LCD.write("message 2") *wait period** }//if no response keep waiting
For **wait period** I was thinking of:
for (int x=0;x<100;x++) { getBS2Data(); //gets switch states and stores as class boolean variable if(switchIsPressed) break; //intended for while loop above CPU.delay(10); }
however, the "break" breaks away from the IF statement, not the main while loop. I hope this makes sense.
So I'm just trying to implement a simple, user friendly quick responding interface but it is turning out to be pretty complicated. This is my first time doing something like this, any input on how to best implement this would be greatly appreciated, thanks.
Comments
See attachement. Note that I wrote the check routine
to wait for a specific value to be received within a timeout period.
You could pass both the specific value and the timeout value
as parameters to the check routine, to make it more general.
regards peter
Post Edited (Peter Verkaik) : 8/23/2006 6:03:12 AM GMT
regards peter
Is there a way to do this without a timer?
(comment out some code that uses a VP but does not involve this code)
public·static·boolean·waitForResponse(int·msTimeout)
··{
··· int mscount = 0;
····timer.mark();
····while(!timer.timeout(msTimeout))
····{
······getAndSendBS2Data();
······if(pushButton||switch4)··//boolean·values·received·from·BS2
········return·true;
······mscount++;
····}
··· System.out.println(mscount); //display mscount value corresponding to msTimeout
····return·false;
··}
Make sure not to press a button so waitForResponse() returns false and displays mscount.
Then change the code to
public·static·boolean·waitForResponse(int·mscount)
··{
····for (int i=0; i<mscount; i++)
····{
······getAndSendBS2Data();
······if(pushButton||switch4)··//boolean·values·received·from·BS2
········return·true;
····}
····return·false;
··}
This only works if the getAndSendBS2Data() never waits for data. If there is data it updates
some flags, if there is no data (use uart.bytAvailable()) it should return immediately.
regards peter
It is better to have the Timer object. You can have as many timers as you
want and it still uses only 1 VP.
Transmit uarts can be stopped until needed, as can adc VP for slowly changing
signals (like monitoring a battery voltage), so there are ways to free VP slots
which gives you the ability to use more than 6 VP, though only 6 VP
can be active simultaneously.
regards peter
vp0: Timer
vp1: receive uart1 or dac1/pwm1
vp2: receive uart2 or dac2/pwm2
vp3: receive uart3 or dac3/pwm3
vp4: receive uart4 or dac4/pwm4
vp5: half duplex receive uart5, transmit uarts 1-5, adc for slow signals
This allows me at least 9 VP's.
More vp's are possible in case of receive uarts used in half duplex operation
where the javelin acts as master (eg. nothing is received until some message has been sent)
The above setup allows me to receive 4 serial streams continuesly.
regards peter