I have subscribed to the Netduino Forum in December 2010 and have followed all the topics with great anticipation - waiting for my N+! I eventually received it and decided to start with something simple to test (being a newbie with C#).
I have connected a potentiometer and are reading the voltage back and are also writing the value to a file on the SD.
This all seems to work great - until I add a Thread.Sleep to the while statement. The file is created but have no content (0Kb). If I remove the Thread.Sleep again - the file is there with data. Am I missing something very basic and simple?
The code below:
Regards
Albert
P.S. What a great community!
using System.Threading; using System.IO; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.NetduinoPlus; namespace Potentiometer { public class Program { public static void Main() { const double MAXVOLTAGE = 3.30; const int DIGITALRANGE = 1024; OutputPort LED = new OutputPort(Pins.ONBOARD_LED, false); AnalogInput POT = new AnalogInput(Pins.GPIO_PIN_A5); Directory.SetCurrentDirectory("\\SD"); using (StreamWriter w = new StreamWriter("abc.txt")) while (true) { LED.Write(!LED.Read()); int RAW = POT.Read(); double VOLTAGE = (RAW * MAXVOLTAGE) / DIGITALRANGE; w.WriteLine(VOLTAGE.ToString("f4")); Debug.Print(VOLTAGE.ToString("f4")); // Thread.Sleep(100); } } } }
Edited by Chris Walker, 28 March 2011 - 04:17 PM.
Added code tags