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

VB Example - Analog Inputs and PWM


  • Please log in to reply
8 replies to this topic

#1 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 16 June 2011 - 02:29 AM

In this example I use two analog inputs and 4 PWM outputs. The purpose of this code is to show the values of the two light sensors (analog inputs) in a creative-ish manner.

First the schematic and breadboard image!
* If anyone notices an error in the schematic please inform me, I might have done it wrong when look at the actual physical breadboard and transferring it to fritzing.

Attached File  schem2.PNG   57.03KB   217 downloads

Attached File  schem.PNG   59.6KB   203 downloads

Code!

Option Strict Off

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

Module Module1
    Sub Main()
        Dim led1 As PWM = New PWM(Pins.GPIO_PIN_D5)
        Dim led2 As PWM = New PWM(Pins.GPIO_PIN_D6)
        Dim led3 As PWM = New PWM(Pins.GPIO_PIN_D9)
        Dim led4 As PWM = New PWM(Pins.GPIO_PIN_D10)

        Dim lightSensor0 As AnalogInput = New AnalogInput(Pins.GPIO_PIN_A0)
        Dim lightSensor1 As AnalogInput = New AnalogInput(Pins.GPIO_PIN_A1)

        Dim val1 As Integer = 0
        Dim val2 As Integer = 0

        lightSensor0.SetRange(0, 50)
        lightSensor1.SetRange(0, 50)

        Do While True
            val1 = lightSensor0.Read()
            val2 = lightSensor1.Read()

            led1.SetDutyCycle(val1)
            led2.SetDutyCycle(val2)

            led3.SetDutyCycle(val1 + val2)
            led4.SetDutyCycle(val1 * val2)
        Loop


    End Sub

End Module

Hope that helps the VB users out. Feel free to ask any questions.

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 16 June 2011 - 02:45 AM

Nice Omar!
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 16 June 2011 - 05:43 AM

Nice Omar!


Thanks! ^_^ I like your examples too!

#4 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 16 June 2011 - 06:06 AM

Wow, Omar. You're learning VB to help out other community members? How awesome is that? Chris

#5 Nizze

Nizze

    Member

  • Members
  • PipPip
  • 12 posts

Posted 15 August 2011 - 01:46 PM

Hi What is the max value for "SetDutyCycle(x)" // Nizze

#6 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 15 August 2011 - 02:19 PM

Hi
What is the max value for "SetDutyCycle(x)"

// Nizze


its 100... i think if you put in anything higher it just sets it to 100 because it wont throw an exception.

#7 Nizze

Nizze

    Member

  • Members
  • PipPip
  • 12 posts

Posted 15 August 2011 - 07:17 PM

its 100... i think if you put in anything higher it just sets it to 100 because it wont throw an exception.



Okey .

I have almost figured that out now .
Thanks for your answer.

Br

Nizze

#8 Guest_jessesteinen_*

Guest_jessesteinen_*
  • Guests

Posted 12 May 2013 - 07:19 AM

As I just found out myself, setrange is deprecated and you can either manually add the [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]SecretLabs.NETMF.Hardware.[/color][font="helvetica, arial, sans-serif;background-color:rgb(255,255,0);color:rgb(255,0,0);"]AnalogInput [/font]assembly as explained here http://forums.netdui...trange/?p=43212

 

 
 

or update your code to use scale instead

 

 

        Dim lightSensor0 As AnalogInput = New AnalogInput(Pins.GPIO_PIN_A0)        Dim lightSensor1 As AnalogInput = New AnalogInput(Pins.GPIO_PIN_A1)        Dim val1 As Integer = 0        Dim val2 As Integer = 0        lightSensor0.Scale = 50        lightSensor1.Scale = 50

 

Hope this helps someone else!



#9 Regan222

Regan222

    New Member

  • Members
  • Pip
  • 6 posts

Posted 24 July 2013 - 04:19 AM

Thanks for the code samples.  Perhaps you could help me with a difficulty I am having.  I am trying to us VB to get a Netduino to run a servo. I have the 4.2 version of the micro-framework and am unable to find PWM in the Microsoft.SPOT.hardware name space.  I use Visual Studio 2010 and can not install the 4.3 micro framework.  Am I just out of luck.  I have a reference to the SPOT name space but when I enter PWM into the code to "Dim" it, the intellisense tells me there is no such thing.  Please help.






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.