'*****************************************************
'   Code by ROF Electronics @2015-017
'   Coder: Bruno Fascendini (info@rofelectronics.com)
'   Use at your own risk without warranty
'*****************************************************

Public Class Form1

    Private ledwiz As LEDWiz

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ledwiz = New LEDWiz(IntPtr.Zero)

        ledwiz.StartupLighting()

        For i As Integer = 0 To ledwiz.NumDevices - 1
            ledwiz.PBA(i, New Byte() {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})  'all OFF by default
            ledwiz.SBA(i, 255, 255, 255, 255, 2)            'enable all 32 outputs to light with current values
        Next

        Timer1.Enabled = True   'Timer to make manual ramp up / down
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Static updown As Boolean = False
        Static onval As Integer = 0

        If updown = False Then  'next ramp value
            onval += 1
        Else
            onval -= 1
        End If
        If onval Mod 49 = 0 Then updown = Not updown 'change direction of ramp in limits

        For i As Integer = 0 To ledwiz.NumDevices - 1   'send values to all present LEDWiz Devices
            ledwiz.PBA(i, New Byte() {onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval, onval})
        Next
    End Sub

    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        ledwiz.Dispose()    'clean up your mess
    End Sub

End Class
