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.
Photo

VBA Questions About Events and Analogs


  • Please log in to reply
2 replies to this topic

#1 STGMavrick

STGMavrick

    New Member

  • Members
  • Pip
  • 1 posts

Posted 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!



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 06 August 2015 - 04:33 AM

Hi STGMavrick,

I was just looking through older posts and noticed that you hadn't received any responses to this. Let me see if I can help get you pointed in the right direction.

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.

For debouncing: I recommend just checking the current time. Go ahead and react to the pushbutton--but keep a timer value which stores the "last pushed" time in ms...and if it has been less than 10ms since the last push...ignore the new event. No need for two buttons.

[Also...you may want to use EdgeBoth instead of EdgeLow for your interrupt trigger, so that you can see when the button is released.]

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.

Ah, good observation. The Pins enumeration only works for digital inputs/outputs. Do you have access to the AnalogChannels.ANALOG_PIN_A0, etc. enumeration?

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.


No RTC, but you can do this pretty easily in code. Just subtract the current DateTime from the target DateTime and then set a timer to wake up your logic. There's no battery backup and you do need to set the time after boot--but this should work well.

BTW, welcome to the Netduino community!

Chris

#3 Enrique Gil-Leyva Flores

Enrique Gil-Leyva Flores

    New Member

  • Members
  • Pip
  • 2 posts

Posted 28 November 2016 - 12:36 AM

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.

 

 

 

Hi STGMavrik

 

this is happening because you have not imported the SecretLabs.NETMF.Hardware.Analog refence

 

Best Regards,

 

Enrique






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.