public void Initialize() { analogTemperature = new AnalogTemperature(MeadowApp.Device, MeadowApp.Device.Pins.A01, AnalogTemperature.KnownSensorType.LM35); analogTemperature.StartUpdating(TimeSpan.FromSeconds(30)); analogTemperature.TemperatureUpdated += AnalogTemperatureUpdated; }
public MeadowApp() { Console.WriteLine("Initializing..."); // configure our AnalogTemperature sensor analogTemperature = new AnalogTemperature( device: Device, analogPin: Device.Pins.A00, sensorType: AnalogTemperature.KnownSensorType.LM35 ); // Example that uses an IObersvable subscription to only be notified // when the temperature changes by at least a degree. analogTemperature.Subscribe(new FilterableObserver <AtmosphericConditionChangeResult, AtmosphericConditions>( h => { Console.WriteLine($"Temp changed by a degree; new: {h.New.Temperature}, old: {h.Old.Temperature}"); }, e => { return(Math.Abs(e.Delta.Temperature) > 1); } )); // classical .NET events can also be used: analogTemperature.Updated += (object sender, AtmosphericConditionChangeResult e) => { Console.WriteLine($"Temp Changed, temp: {e.New.Temperature}°C"); }; // Get an initial reading. ReadTemp().Wait(); // Spin up the sampling thread so that events are raised and // IObservable notifications are sent. analogTemperature.StartUpdating(); }
public MeadowApp() { Initialize(); LoadScreen(); analogTemperature.StartUpdating(TimeSpan.FromSeconds(5)); }
public App() { ConfigurePorts(); //BeginReadingTemp(); ReadInitialTemperature().Wait(); // start the temp sensor update loop temperatureSensor.StartUpdating(); }
private static AnalogTemperature InitializeAnalogTemperatureSensor(EventHandler <AtmosphericConditionChangeResult> updatedHandler) { Console.WriteLine("Initializing analog temperature sensor..."); AnalogTemperature analogTemperature = new AnalogTemperature( device: Device, analogPin: Device.Pins.A00, sensorType: AnalogTemperature.KnownSensorType.LM35 ); analogTemperature.Updated += updatedHandler; analogTemperature.StartUpdating(); return(analogTemperature); }
void Initialize() { onboardLed = new RgbPwmLed( device: Device, redPwmPin: Device.Pins.OnboardLedRed, greenPwmPin: Device.Pins.OnboardLedGreen, bluePwmPin: Device.Pins.OnboardLedBlue); onboardLed.SetColor(Color.Red); onboardLed.SetColor(Color.Blue); analogTemperature = new AnalogTemperature(Device, Device.Pins.A00, sensorType: AnalogTemperature.KnownSensorType.LM35); analogTemperature.StartUpdating(TimeSpan.FromMinutes(5)); displayView = new DisplayView(); onboardLed.SetColor(Color.Green); }
public MeadowApp() { var led = new RgbLed(Device, Device.Pins.OnboardLedRed, Device.Pins.OnboardLedGreen, Device.Pins.OnboardLedBlue); led.SetColor(RgbLed.Colors.Red); analogTemperature = new AnalogTemperature( device: Device, analogPin: Device.Pins.A00, sensorType: AnalogTemperature.KnownSensorType.LM35 ); analogTemperature.Updated += AnalogTemperatureUpdated; var config = new SpiClockConfiguration( speedKHz: 6000, mode: SpiClockConfiguration.Mode.Mode3); st7789 = 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 ); displayWidth = Convert.ToInt32(st7789.Width); displayHeight = Convert.ToInt32(st7789.Height); graphics = new GraphicsLibrary(st7789); graphics.Rotation = GraphicsLibrary.RotationType._270Degrees; led.SetColor(RgbLed.Colors.Green); LoadScreen(); analogTemperature.StartUpdating(); }
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); }