void InitializePeripherals() { ledBarGraph = new LedBarGraph( new Microsoft.SPOT.Hardware.Cpu.Pin[10] { N.Pins.GPIO_PIN_D0, N.Pins.GPIO_PIN_D1, N.Pins.GPIO_PIN_D2, N.Pins.GPIO_PIN_D3, N.Pins.GPIO_PIN_D4, N.Pins.GPIO_PIN_D5, N.Pins.GPIO_PIN_D6, N.Pins.GPIO_PIN_D7, N.Pins.GPIO_PIN_D8, N.Pins.GPIO_PIN_D12 } ); rgbPwmLed = new RgbPwmLed ( redPin: N.PWMChannels.PWM_PIN_D11, greenPin: N.PWMChannels.PWM_PIN_D10, bluePin: N.PWMChannels.PWM_PIN_D9, redLedForwardVoltage: 1.05f, greenLedForwardVoltage: 1.5f, blueLedForwardVoltage: 1.5f ); rgbPwmLed.StartPulse(Netduino.Foundation.Color.Red); displayController = new DisplayController(); displayController.DrawText("Connecting..."); humiditySensorController = new HumiditySensorController ( analogPort: N.Pins.GPIO_PIN_A0, digitalPort: N.Pins.GPIO_PIN_D13 ); }
void Initialize() { Console.WriteLine("Initialize hardware..."); onboardLed = new RgbPwmLed(device: Device, redPwmPin: Device.Pins.OnboardLedRed, greenPwmPin: Device.Pins.OnboardLedGreen, bluePwmPin: Device.Pins.OnboardLedBlue, 3.3f, 3.3f, 3.3f, Meadow.Peripherals.Leds.IRgbLed.CommonType.CommonAnode); onboardLed.SetColor(Color.Red); button = new PushButton(Device, Device.Pins.D04, ResistorMode.InternalPullUp); button.Clicked += ButtonClicked; var config = new SpiClockConfiguration ( speedKHz: 6000, mode: SpiClockConfiguration.Mode.Mode3 ); var display = new St7789 ( device: Device, spiBus: Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config), chipSelectPin: Device.Pins.D02, dcPin: Device.Pins.D01, resetPin: Device.Pins.D00, width: 240, height: 240 ); displayController = new DisplayController(display); capacitive = new Capacitive( device: Device, analogPin: Device.Pins.A01, minimumVoltageCalibration: MINIMUM_VOLTAGE_CALIBRATION, maximumVoltageCalibration: MAXIMUM_VOLTAGE_CALIBRATION); capacitive.Subscribe(new FilterableChangeObserver <FloatChangeResult, float>( handler => { onboardLed.SetColor(Color.Purple); displayController.UpdateMoistureImage(handler); displayController.UpdateMoisturePercentage(handler.New, handler.Old); onboardLed.SetColor(Color.Green); }, filter => { return(Math.Abs(filter.Delta) > 0.05); } )); capacitive.StartUpdating( sampleCount: 10, sampleIntervalDuration: 40, standbyDuration: (int)TimeSpan.FromHours(1).TotalMilliseconds); analogTemperature = new AnalogTemperature(Device, Device.Pins.A00, AnalogTemperature.KnownSensorType.LM35); analogTemperature.Subscribe(new FilterableChangeObserver <AtmosphericConditionChangeResult, AtmosphericConditions>( handler => { onboardLed.SetColor(Color.Purple); displayController.UpdateTemperatureValue(handler.New.Temperature.Value, handler.Old.Temperature.Value); onboardLed.SetColor(Color.Green); }, filter => { return(Math.Abs(filter.Delta.Temperature.Value) > 1f); } )); analogTemperature.StartUpdating( sampleCount: 10, sampleIntervalDuration: 40, standbyDuration: (int)TimeSpan.FromHours(1).TotalMilliseconds); onboardLed.SetColor(Color.Green); }
void Initialize() { onboardLed = new RgbPwmLed( device: Device, redPwmPin: Device.Pins.OnboardLedRed, greenPwmPin: Device.Pins.OnboardLedGreen, bluePwmPin: Device.Pins.OnboardLedBlue); onboardLed.SetColor(Color.Red); button = new PushButton(Device, Device.Pins.D04, ResistorMode.InternalPullUp); button.Clicked += ButtonClicked; var config = new SpiClockConfiguration( speed: new Frequency(48000, Frequency.UnitType.Kilohertz), mode: SpiClockConfiguration.Mode.Mode3); var spiBus = Device.CreateSpiBus( clock: Device.Pins.SCK, copi: Device.Pins.MOSI, cipo: Device.Pins.MISO, config: config); var display = new St7789 ( device: Device, spiBus: spiBus, chipSelectPin: Device.Pins.D02, dcPin: Device.Pins.D01, resetPin: Device.Pins.D00, width: 240, height: 240 ); displayController = new DisplayController(display); capacitive = new Capacitive( device: Device, analogPin: Device.Pins.A01, minimumVoltageCalibration: MINIMUM_VOLTAGE_CALIBRATION, maximumVoltageCalibration: MAXIMUM_VOLTAGE_CALIBRATION); var capacitiveObserver = Capacitive.CreateObserver( handler: result => { onboardLed.SetColor(Color.Purple); displayController.UpdateMoistureImage(result.New); displayController.UpdateMoisturePercentage(result.New, result.Old.Value); onboardLed.SetColor(Color.Green); }, filter: null ); capacitive.Subscribe(capacitiveObserver); capacitive.StartUpdating(TimeSpan.FromHours(1)); analogTemperature = new AnalogTemperature(Device, Device.Pins.A00, AnalogTemperature.KnownSensorType.LM35); var analogTemperatureObserver = AnalogTemperature.CreateObserver( handler => { onboardLed.SetColor(Color.Purple); displayController.UpdateTemperatureValue(handler.New, handler.Old.Value); onboardLed.SetColor(Color.Green); }, filter: null ); analogTemperature.Subscribe(analogTemperatureObserver); analogTemperature.StartUpdating(TimeSpan.FromHours(1)); onboardLed.SetColor(Color.Green); }