So the Variable Resistor (POT) was cool and really easy.  So there is another sensor in the box which should work pretty much the same way.  The thermometer also has a red, black, and white wire so this tells me it works the same way.  Analog circuit based thermometers are called thermistors which mean they are variable resistors that change the impedance based on a temperature.  So my code should look the same as my Day 1's blog entry.

I added a debug statement to output the actual thermometer value.  I quickly noticed that my room temperature reading was a 422 or 424.

public static void Main()
{
    OutputPort led = 
new OutputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.ONBOARD_LED, false); AnalogInput variableResistor =
new AnalogInput(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_A0); while (true) { led.Write(!led.Read()); Thread.Sleep(variableResistor.Read()); Debug.Print(variableResistor.Read().ToString()); } }

The output window looked like this:

423
422
423
423
422
422
422

So breathing on the thermometer yielded about a 500 reading.  So there was a 78 point difference, the LED was blinking slower as the temperature went up but not noticeably.  So enter some math to make the spread more apparent.  I decided on a simple algorithm, take the value from the thermometer, subtract 422 to get the difference and multiply by 10.  I figure this would generate a more obvious change in blink rate.

I added the System.Math.Abs() method call to ensure that I did not pass a negative number to the Thread.Sleep() method call.  The code looks like this and flashes faster as the temperature nears room temperature and slower as it gets warmer.

public static void Main()
{
    OutputPort led = 
new OutputPort(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.ONBOARD_LED, false); AnalogInput variableResistor =
new AnalogInput(SecretLabs.NETMF.Hardware.NetduinoPlus.Pins.GPIO_PIN_A0); while (true) { led.Write(!led.Read()); Thread.Sleep(System.Math.Abs((variableResistor.Read() - 422) * 10)); Debug.Print(variableResistor.Read().ToString()); } }