B4R Library rEasyBuzzer

A B4R wrap for this Github project. The attached B4R project plays the very famous Nokia Tune making use of a passive buzzer. Explore the other methods exposed by the library...

Sure you will know what to do with the attached lib files. B4R project also attached.

Enable rEasyBuzzer in the libs tab of the B4R IDE.

Nokia Tune frequency and timing comes from here

EazyBuzzer_bb.png


Sample code to play the Nokia Tune:

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Dim eb As EasyBuzzer
    Dim t As Timer
    
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    t.Initialize("t_tick", 10)
    eb.initialize
    eb.Pin = 5
'    eb.OnDuration = 500                           'On Duration in ms
'    eb.OffDuration = 500                          'Off Duration in ms
'    eb.beepFreqAndNoOfTimes(1000, 10)             'This call uses OnDuration and OffDuration
'   eb.singleBeep(5000, 2000)                     'Make a single beep at Freq = 5000 Hz and Duration = 2000 ms

'    eb.beepSequence(1500, 200, 100, 7, 2000, 3)

    Delay(500)

    AddLooper("myLopper")
    
    t.Enabled = True
    
'    eb.beepContinuously(1500)
    
End Sub

Sub t_tick
    
    eb.update                                     'call this frequently to update the buzzer
    
End Sub

Sub myLopper
    
    'play the famous Nokia Tune
    eb.singleBeep(1319,133)
    Delay(143)
    eb.singleBeep(1175,133)
    Delay(143)
    eb.singleBeep(740,267)
    Delay(277)
    eb.singleBeep(831,267)
    Delay(277)
    eb.singleBeep(1109,133)
    Delay(143)
    eb.singleBeep(988,133)
    Delay(143)
    eb.singleBeep(587,267)
    Delay(277)
    eb.singleBeep(659,267)
    Delay(277)
    eb.singleBeep(988,133)
    Delay(143)
    eb.singleBeep(880,133)
    Delay(143)
    eb.singleBeep(554,267)
    Delay(277)
    eb.singleBeep(659,267)
    Delay(277)
    eb.singleBeep(880,533)
    Delay(1000)
    eb.stopBeep
    Delay(2000)
    
End Sub
 

Attachments

  • b4rEasyBuzzer.zip
    1.1 KB · Views: 497
  • rEasyBuzzer.zip
    5.1 KB · Views: 495
Top