Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

STGMavrick

Member Since 19 Feb 2014
Offline Last Active Dec 08 2014 03:40 PM
-----

Topics I've Started

VBA Questions About Events and Analogs

08 December 2014 - 03:40 PM

Hi,

I've got some questions that are stumping me. I purchased a Netduino Plus 2 a while ago and never really tinkered with it until I decided to do some light controls for the Christmas tree. I'm a PLC programmer by day and it's driving me nuts that what I want to do I would already have done in ladder logic in a matter of minutes. But I'm persistent and determined to learn this thing so here we go.

 

I'm trying to use a single pushbutton to turn lights on and off.  I used the eventhandler example posted on the boards here but I kept running into debouncing issues with the button and I did not know how to add a duration of button press so I switched to two buttons.
 

Imports Microsoft.SPOT
Imports Microsoft.SPOT.Hardware
Imports SecretLabs.NETMF.Hardware
Imports SecretLabs.NETMF.Hardware.Netduino

Module Module1

    Dim ButtonState As Boolean = True
    Dim led As New OutputPort(Pins.GPIO_PIN_D1, False)
    Dim Potentiometer As AnalogInput = New AnalogInput(Cpu.AnalogChannel.ANALOG_0)
    Dim ScaledValue As Double = 0

    Sub Main()
        Dim ButtonOff As InterruptPort = New InterruptPort(Pins.GPIO_PIN_D0, False, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow)
        AddHandler ButtonOff.OnInterrupt, AddressOf ButtonChangeHigh
        ButtonOff.EnableInterrupt()

        Dim ButtonOn As InterruptPort = New InterruptPort(Pins.GPIO_PIN_D2, False, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow)
        AddHandler ButtonOn.OnInterrupt, AddressOf ButtonChangeLow
        ButtonOn.EnableInterrupt()

        While ButtonState = True
            Potentiometer.Scale = 1000
            ScaledValue = Potentiometer.Read()

            led.Write(True)
            Thread.Sleep(ScaledValue)
            led.Write(False)
            Thread.Sleep(ScaledValue)

        End While

        Do
            Thread.Sleep(Timeout.Infinite)
        Loop

    End Sub

    Sub ButtonChangeHigh(data1 As UInteger, data2 As UInteger, time As Date)

        ButtonState = True

    End Sub

    Sub ButtonChangeLow(data1 As UInteger, data2 As UInteger, time As Date)

        ButtonState = False

    End Sub

End Module

So, What I'm seeing is that If I declare buttonstate as true initially I can turn it off.  However, I cannot turn it on again. I'm assuming I am not doing it correctly. Ideally though I would prefer a single pushbutton to toggle the system on and off.

Secondly, My Analog input declaration would not work with my code I have written unless I used CPU.AnalogChannel.AnalogChannel_0. Pins.GPIO_PIN_A0 would complain about implicit conversion.

 

Thirdly, do these have RTC abilities? I originally wanted to have two modes. Manual on/off and time controlled. Start at X hour, stop at y hour.

I appreciate your help!


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.