Author Topic: Connection Problem  (Read 922 times)

helge

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Connection Problem
« on: July 20, 2016, 02:18:27 pm »
Its strange, because the other module which has the same code in a ButtonPressed event works.

Code: [Select]
Class TSL2561Example
    Shared luminosity As TSL2561
    Shared _init As Boolean
   
    Shared Event Boot()
        luminosity = New TSL2561(TSL2561.TSL2561_ADDR_FLOAT)
        _init = luminosity.Begin()
    End Event
   
    Shared Event Report() RaiseEvent Every 30 Seconds
        Dim payload As ListOfByte = New ListOfByte
        Dim payString As String = ""
       
        If _init = True Then
            LedRed = True
            payString = "1"
        Else
            LedRed = False
            payString = "0"
        End If
        payload.Add(payString)
        Lplan.Publish("mcThings/TSL2561Example/Init", payload)
        Thread.Sleep(10000)
        Thread.ClearHardwareEvent()
        LedRed = False
    End Event
End Class

=================================================================
Class TSL2561
 Public Sub New(addr As Byte)
        gI2C = I2c.Create(I2C_SPEED, Pin.SCL, Pin.SDA, addr)
        gAddr = New ListOfByte()
        gData = New ListOfByte()
        _integration = TSL2561_INTEGRATIONTIME_13MS
        _gain = TSL2561_GAIN_16X
    End Sub
   
    Public Function Begin() As Boolean
        Dim dataByte As Byte
        dataByte = ReadSingleByte(TSL2561_REGISTER_ID)
        dataByte = dataByte & 0x0a
        If (dataByte > 0) Then
            SetTiming(_integration)
            SetGain(_gain)
            _initialized = True
            Disable()
            Return True
        Else
            Return False
        End If
.
.
.
    End Function