Netduino home hardware projects downloads community

Jump to content


Photo

Multithread Problem 3 blinking LED's


Best Answer liqdfire, 20 March 2014 - 02:56 AM

See if this is any better, I already put my logic analyzer away. 

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.NetduinoPlus

Module Module1

    Dim led1 As New OutputPort(Pins.GPIO_PIN_D0, False)
    Dim led2 As New OutputPort(Pins.GPIO_PIN_D1, False)
    Dim led3 As New OutputPort(Pins.GPIO_PIN_D2, False)
    Dim led4 As New OutputPort(Pins.GPIO_PIN_D3, False)

    Private _thread1Wait As AutoResetEvent
    Private _thread2Wait As AutoResetEvent
    Private _thread3Wait As AutoResetEvent

    Private _threadX As Thread
    Private _threadY As Thread
    Private _threadZ As Thread

    Sub Main()

        _thread1Wait = New AutoResetEvent(False)
        _thread2Wait = New AutoResetEvent(False)
        _thread3Wait = New AutoResetEvent(False)

        _threadX = New Thread(AddressOf led1t)
        _threadY = New Thread(AddressOf led2t)
        _threadZ = New Thread(AddressOf led3t)


        _threadX.Start()
        _threadY.Start()
        _threadZ.Start()

        _thread1Wait.Set()
        _thread2Wait.Set()
        _thread3Wait.Set()

        System.Threading.WaitHandle.WaitAll(New System.Threading.AutoResetEvent() {_thread1Wait, _thread2Wait, _thread3Wait})

        led4.Write(True)
        Thread.Sleep(Timeout.Infinite) ' Call this here or your program will exit..
    End Sub

    Sub led1t()
        _thread1Wait.WaitOne()

        Dim x As Integer = 0

        While x < 30
            x += 1
            led1.Write(True)
            Thread.Sleep(25)
            led1.Write(False)
            Thread.Sleep(25)
            Debug.Print("Led1 Blink Count = " & x.ToString)
        End While

        _thread1Wait.Set()
        _threadZ.Join()
    End Sub

    Sub led2t()
        _thread2Wait.WaitOne()

        Dim y As Integer = 0

        While y < 15
            y += 1
            led2.Write(True)
            Thread.Sleep(25)
            led2.Write(False)
            Thread.Sleep(25)
            Debug.Print("Led2 Blink Count = " & y.ToString)
        End While

        _thread2Wait.Set()
        _threadZ.Join()
    End Sub

    Sub led3t()
        _thread3Wait.WaitOne()

        Dim z As Integer = 0

        While z < 55
            z += 1
            led3.Write(True)
            Thread.Sleep(25)
            led3.Write(False)
            Thread.Sleep(25)
            Debug.Print("Led3 Blink Count = " & z.ToString)
        End While

        _thread3Wait.Set()
    End Sub

End Module

Go to the full post


  • Please log in to reply
20 replies to this topic

#21 twinnaz

twinnaz

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationBrampton, Ontario

Posted 20 March 2014 - 03:17 AM

Thanks once again

Netduino Plus 2





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.