View previous topic :: View next topic |
Author |
Message |
Joaquim Guest
|
BUZZER |
Posted: Thu Apr 28, 2005 7:47 am |
|
|
Hello,
i wanted to know how i could do to switch on a buzzer 2 seconds and then switch it off, every 2 seconds during 1 minute and then after this 1 minute
do the same thing every 30 seconds instead of every 2 second...
I hope this is clear.
during 60s
{
BUZZER ON
2s
BUZZER OFF
}
then
every 30 s
{
BUZZER ON
2s
BUZZER OFF
}
Many thanks !! |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Thu Apr 28, 2005 9:11 am |
|
|
This sounds like a school homework assignment and you don't know where to start.
1) Find out how to turn an I/O pin on and off using output_high(pin) and related functions.
2) Learn how to wait lengths of time using delay_ms(time).
3) Learn how to loop using while().
4) Use a combination of slow loops to set you buzzer control pin.
That is all there is to it.
Also, look at a few of the example programs that come with the compiler. When you have time it pays to read the manual cover to cover. You will find all sorts of neat stuff. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
Joaquim Guest
|
|
Posted: Thu Apr 28, 2005 9:24 am |
|
|
My main problem is to delay in a delay...
I don't know how to do that ....
During 60 s do something every 2 s ...
Could someone help me to write that ? |
|
|
Joaquim Guest
|
|
Posted: Thu Apr 28, 2005 9:59 am |
|
|
I'll try this way.
Any other suggestion ?
Thank you ! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Apr 28, 2005 12:12 pm |
|
|
Use a for() loop to control this. Since you know the total amount
of time that you want your action to occur, and you know the amount
of time for one sequence, just divide the total time by the sequence
time. This gives you the number of loops that you want to do.
In your example:
The buzzer is on for 2 and off for 2 seconds. Total = 4 seconds
for the sequence.
The total time for the action is 60 seconds. Divide 60 by 4, which
gives 15. This is the number of loops that you need.
Then use a for() loop to do this:
Code: | #define BUZZER_PIN PIN_B0
main()
{
int8 i;
for(i = 0; i < 15; i++)
{
output_high(BUZZER_PIN); // Turn on the buzzer
delay_ms(2000); // Wait for 2 seconds
output_low(BUZZER_PIN); // Turn off the buzzer
delay_ms(2000); // Wait for 2 seconds
}
while(1); // Don't let PIC fall off the end and go to sleep.
} |
Do you understand the math and the concept here ? |
|
|
Joaquim Guest
|
|
Posted: Fri Apr 29, 2005 1:53 am |
|
|
Thank you !!!
It is what i wanted !
Many thanks !!! |
|
|
fuzzy
Joined: 26 Feb 2005 Posts: 64
|
|
Posted: Thu May 05, 2005 12:43 pm |
|
|
I think you better use internal PIC counter... it's more useful and precise. |
|
|
|