Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Time the beeper

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
victorf



Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York

Posted: 31 October 2006, 17:59 PM    Post subject: Time the beeper Reply with quote

I have a piezo-buzzer attached to a zx-24 pin. I wish to sound the buzzer every t - 5 seconds for 5 seconds where t could be 15, 30 or 60 seconds beginning when a specific switch is set on. The buzzer must continue its beep cycle until the switch is set off. I would like the timing cycle to be fairly accurate, say within 0.1 second or so.

How can I do this elegantly? Smile

Any enlightenment will be appreciated.

Vic
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 31 October 2006, 18:25 PM    Post subject: Reply with quote

If not already being used, the interval timer would be useful for this purpose. Here is some sample code that I believe does what you want. The Main() shows how to set the beeper period which can be set to a value of 5 or less for no beeping. The beeper is activated for all but 5 seconds of the period.

The code assumes a buzzer that is activated with a logic zero on an output pin.

Code:
Private Const beepPin as Byte = C.0
Private Const beepOff as Byte = 5
Private beepPeriod as Byte
Private beepStack(1 to 25) as Byte

Sub Main()
   ' start the beeper task
   CallTask beepTask, beepStack

   [ other code here ]

   ' set the desired beep period
   beepPeriod = 10
End Sub

Private Sub beepTask()
   Do
      If (beepPeriod > beepOff) Then
         ' activate the buzzer
         Call PutPin(beepPin, zxOutputLow)

         ' set an interval timer for the beep time
         Call SetInterval(CSng(beepPeriod - beepOff))
         Call WaitForInterval(0)
         
         ' deactivate the buzzer
         Call PutPin(beepPin, zxOutputHigh)

         ' set an interval timer for the beep off time
         Call SetInterval(CSng(beepOff))
         Call WaitForInterval(0)

         ' uncomment this line for a "one-shot" beep
'         beepPeriod = 0
      Else
         beepPeriod = 0
         Sleep(0.05)
      End If
   Loop
End Sub
Back to top
victorf



Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York

Posted: 01 November 2006, 14:02 PM    Post subject: Reply with quote

Don,

Thanks for the Beeper task code. I guess I was not clear as to how I wanted things to work. I want to set an interval, say 15 seconds, and have the beeper go off at the last 5 seconds of the interval. The 15 seconds is the timing between observations and the last 5 seconds - beeping - is to alert the operator that the end of the period is approaching. I can re-arrange the code to do this.

I am already running a task to handle the keypress strobe from my keypad which you have previously suggested. How will this new task effect the keystrobe task. It is important that the timing interval for the beeper task be within 0.1 or 0.2 seconds of the scheduled period.

Any further enlightenment will be appreciated.
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 01 November 2006, 16:03 PM    Post subject: Reply with quote

I misread your original description but the code can be easily changed to meet your needs.
victorf wrote:
I am already running a task to handle the keypress strobe from my keypad which you have previously suggested. How will this new task effect the keystrobe task.

Given the time periods involved, I would guess that neither task will effect the other appreciably. Keep in mind that the task switching interval is 1.95mS.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group