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

Can I convert an int to a word with N+2, running 4.2.2?


Best Answer NooM, 10 July 2013 - 08:00 AM

first: its const int maxAdcValue = 4095;

 

than:

what you mean with "word" = a word is 2 bytes ...

or you mean text?

 

text:

 

Strint textValue = "";

 

if (rawValue > 50)

{

textValue = "bigger 50";

}

else

{

textValue = "smaller 50";

}

Debug.Print(textValue);

Go to the full post


  • Please log in to reply
2 replies to this topic

#1 Buddy

Buddy

    Member

  • Members
  • PipPip
  • 17 posts

Posted 10 July 2013 - 12:26 AM

NOOB Alert! :unsure:

 

I am using the following to receive an input from a sensor on port A0. The port has a sensor that sends either 0V or 3.3V; nothing really in between. This part works flawlessly.

 

My goal is to receive that voltage and to convert 0V to one word and 3.3V to a different word.

 

I have tried rearranging and recoding based on samples from the web with no luck. Please offer any constructive advice on how to reach the goal.

using System;using System.Net;using System.Net.Sockets;using System.Threading;using System.Text.RegularExpressions;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;namespace NetduinoApplication1{    public class Program    {               public static void Main()        {                        const double maxVoltage = 3.3;                        const int maxAdcValue = 4096; // 10-bit Resolution (ADC) change to 4096 for ND+2 as it is 12-bit                        SecretLabs.NETMF.Hardware.AnalogInput mySensor = new SecretLabs.NETMF.Hardware.AnalogInput(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_A0);                        while (true)                        {                            int rawValue = mySensor.Read();                            double value = (rawValue * maxVoltage) / maxAdcValue;                            //based on the calculations above, I get small ranges.                             //1-5 if the sensor voltage is 0V                            //1000-1005 if the sensor is sending 3.3V to the N+2.                            {                                    //Using this to provide a clean difference instead                                    //instead of the small ADC ranges of 1-5 or 1000-1005                                    if (rawValue > 50)							                                           //This is a random number that I picked.							        //I would prefer to simply convert the word here, if possibe.                                                                     rawValue = 1111;                                                                         //This is a random number that I picked.                                     //I would prefer to simply convert the word here, if possibe.                                else rawValue = 2222;                            }                            Debug.Print(rawValue.ToString());                            Thread.Sleep(1300);                        }        }    }}

Not sure if it matters but here's a debug of it running.

 

Found debugger!

Create TS.

Loading start at 806a988, end 8085288

 

[Assemblies Removed]

 

 

Resolving.

The debugging target runtime is loading the application assemblies and starting execution.

Ready.

 

[More Removed]

 

The thread '<No Name>' (0x2) has exited with code 0 (0x0).

1111

1111

1111

1111

2222

2222

2222

2222

2222

2222

1111

1111

1111



#2 NooM

NooM

    Advanced Member

  • Members
  • PipPipPip
  • 490 posts
  • LocationAustria

Posted 10 July 2013 - 08:00 AM   Best Answer

first: its const int maxAdcValue = 4095;

 

than:

what you mean with "word" = a word is 2 bytes ...

or you mean text?

 

text:

 

Strint textValue = "";

 

if (rawValue > 50)

{

textValue = "bigger 50";

}

else

{

textValue = "smaller 50";

}

Debug.Print(textValue);



#3 Buddy

Buddy

    Member

  • Members
  • PipPip
  • 17 posts

Posted 10 July 2013 - 04:26 PM

Thanks NooM!






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.