The modules available for .NET Gadgeteer now include some interesting modules by Seeed Studio. This example uses two of them:
The application code is very simple, as shown in the following block.
using Microsoft.SPOT; using GT = Gadgeteer; using Gadgeteer.Modules.GHIElectronics; using Gadgeteer.Modules.Seeed; namespace TempHumidity { public partial class Program { void ProgramStarted() { temperatureHumidity.MeasurementComplete += new TemperatureHumidity.MeasurementCompleteEventHandler(temperatureHumidity_MeasurementComplete); button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed); Debug.Print("Program Started"); } void button_ButtonPressed(Button sender, Button.ButtonState state) { if (button.IsLedOn) { temperatureHumidity.StopContinuousMeasurements(); button.TurnLEDOff(); } else { temperatureHumidity.StartContinuousMeasurements(); button.TurnLEDOn(); } } void temperatureHumidity_MeasurementComplete(TemperatureHumidity sender, double temperature, double relativeHumidity) { double fahrenheit = (temperature * 1.8) + 32; led.TurnOff(); oledDisplay.SimpleGraphics.Clear(); oledDisplay.SimpleGraphics.DisplayText("Temperature: " + fahrenheit, Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Yellow, 5, 40); oledDisplay.SimpleGraphics.DisplayText("Rel Humidity: " + relativeHumidity.ToString(), Resources.GetFont(Resources.FontResources.NinaB), GT.Color.Yellow, 5, 80); if (fahrenheit < 63 || fahrenheit > 75) led.BlinkRepeatedly(GT.Color.Yellow); } } }
Note: Don’t use higher voltage than needed to drive components. Excess power is dissipated as heat. After running this example for a few minutes on this 9 volt battery, the power module was hot. See this discussion on the GHI Electronics forum: http://www.tinyclr.com/forum/21/5013/#/1/msg47518