mc-Things

General Category => mc-Things General Discussion => Topic started by: bailejor on April 28, 2017, 03:43:21 pm

Title: Accelerometer Code Issue
Post by: bailejor on April 28, 2017, 03:43:21 pm
Hello,

I'm attempting to get accelerometer code from the examples of Github working, but whenever I attempt to use it I get "DataType LIS2DH12 is not defined"

I guess it's not clear to me how to make use of the accelerometer library. Here is the code I was attempting to run:

Code: [Select]
Class LISDH12_Test
    Shared accel As LIS2DH12
   
    Shared Event Boot()
        accel = New LIS2DH12
       
        'set accelerometer to cause interrupt if accelation is > 1.15Gs for longer than 2ms (any axis)
        accel.ConfigureShockInterrupt(1.15, 2.0)
    End Event
   
    Shared Event AccelerometerInt1()
        'debounce interrupt
        Thread.Sleep(100000)
        Thread.ClearHardwareEvent()
       
        'Read Int source register to clear interrupt
        If ((accel.GetINT1ActiveInterrupt() & LIS2DH12.INT_ACTIVE) = LIS2DH12.INT_ACTIVE) Then
            'interrupt generated
           
            LedRed = Not LedRed
           
        End If
       
        'restart interrupt       
        accel.SetINT1ActiveInterrupt(LIS2DH12.INT_SRC_XH | LIS2DH12.INT_SRC_YH | LIS2DH12.INT_SRC_ZH)
    End Event
End Class   
Title: Re: Accelerometer Code Issue
Post by: mc-T2 on May 02, 2017, 12:58:44 pm
Hello,
Are you adding the LIS2DH12 library to your code? As an example, open up the temperature example in mcStudio. You'll see that there are two 'tabs' - one is the script and the other is the library. It looks to me that you have not added the library since you are getting the error that 'LIS2DH12 is not defined'

Hope that helps!