NOOB Alert!
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