Author Topic: Accelerometer Events  (Read 818 times)


  • Newbie
  • *
  • Posts: 43
    • View Profile
Re: Accelerometer Events
« on: September 15, 2016, 03:41:40 am »

I'm trying to figure out how to (if possible) use the MMA8652 library provided with the garage example to detect like nock (or tap) events. My use case is to stick the mcModule to a floor lamp and then gently tape the lamp (or module if required) to toggle a network connected LIFX light bulb (I will have Node RED handling this).

This is the code (derived from the garage example) that I am trying to use:

Code: [Select]
Class KnockTest
    Shared accel As MMA8652
    Shared Event Boot()
        accel = New MMA8652   
        accel.ConfigureShockInterrupt(0.1, 0)
    End Event
    Shared Event AccelerometerInt1()
        Dim readByte As Byte = accel.ReadSingleByte(MMA8652.PL_STATUS_REG)
        Dim payload As ListOfByte = New ListOfByte
        Dim payString As String = ""
        If (readByte & 0x80) = 0x80 Then
            'interrupt occured
            payString = readByte.ToString("X#")
        End If
        Lplan.Publish("mcThings/Testing", payload)
    End Event
End Class

I've tried every conceivable value for the threshold and duration with no luck :/

Any tips would be greatly appreciated.