View previous topic :: View next topic |
Author |
Message |
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
ALERT AND GETC() FUNCTION |
Posted: Tue May 10, 2005 8:13 am |
|
|
Hello,
i wondered how i could do if i want to something pretty much like this :
Code: | while(!END_OF_ALERT)
{
END_OF_ALERT = getc();
output_high(BUZZER); // BUZZER ON
output_high(RED_LED); // RED LED ON
delay_ms(5000); // ON for 5 seconds
output_low(BUZZER); // BUZZER OFF
output_low(RED_LED); // RED LED OFF
delay_ms(25000); // OFF for 25 seconds
} |
The trouble is i would like the BUZZERand the RED LED switch on and off waiting while END_OF_ALERT is not 1, but the getc() function is waiting for a caracter on the serial port and doesn't move to this section ...
How can i do to this ? Do you have an idea ? Thanks a lot for your help ! |
|
|
Guest Guest
|
|
Posted: Tue May 10, 2005 8:31 am |
|
|
Look at the function kbhit(). It will tell you if there is a character waiting, rather than waiting for a character.
SherpaDoug |
|
|
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
|
Posted: Tue May 10, 2005 8:48 am |
|
|
Ok, so it should be something pretty much like this ? :
Code: | while(!END_OF_ALERT)
{
if(kbhit()) END_OF_ALERT = getc();
output_high(BUZZER); // BUZZER ON
output_high(RED_LED); // RED LED ON
delay_ms(5000); // ON for 5 seconds
output_low(BUZZER); // BUZZER OFF
output_low(RED_LED); // RED LED OFF
delay_ms(25000); // OFF for 25 seconds
} |
|
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed May 11, 2005 6:41 am |
|
|
That would work, though it would only check for the end of the alarm every ten seconds. If you shut off the alarm and it continues to blare for 9 more seconds most people would assume they failed to shut it off and resort to alternate means like kicking, throwing rocks, or cutting wires! Hold your breath for ten seconds to see how long it can be.
How about a loop that executes every 1/10 second checking if the alarn is supposed to be on or if it should be in mode one or mode two. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
global
Joined: 01 Feb 2005 Posts: 21 Location: Paris
|
|
Posted: Wed May 11, 2005 7:57 am |
|
|
Hello,
how can i do that ? Do you have a code example
Many thanks ! |
|
|
Scott Guest
|
|
Posted: Wed May 11, 2005 8:29 am |
|
|
global wrote: | Hello,
how can i do that ? Do you have a code example
Many thanks ! |
It would be quite similar to the Timer interrupt routine in your "Count 5 minutes if nobody logged in ..." thread
Scott |
|
|
|