void Init() { Console.WriteLine("Init"); portLeft = Device.CreateDigitalInputPort(Device.Pins.D12); portUp = Device.CreateDigitalInputPort(Device.Pins.D13); portRight = Device.CreateDigitalInputPort(Device.Pins.D07); portDown = Device.CreateDigitalInputPort(Device.Pins.D11); var config = new SpiClockConfiguration(12000, SpiClockConfiguration.Mode.Mode0); var bus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config); display = new Ssd1309 ( device: Device, spiBus: bus, chipSelectPin: Device.Pins.D02, dcPin: Device.Pins.D01, resetPin: Device.Pins.D00 ); graphics = new GraphicsLibrary(display); graphics.CurrentFont = new Font4x8(); graphics.Rotation = GraphicsLibrary.RotationType._270Degrees; }
public InputObservableApp() { // create an input port on D02. _input = Device.CreateDigitalInputPort(Device.Pins.D02); // Traditional event _input.Changed += (object sender, DigitalInputPortEventArgs e) => { Console.WriteLine($"Old school event raised; Time: {e.New.Millisecond}, Value: {e.Value}"); }; // this illustrates using a FilterableObserver. Note that the filter is an optional // parameter, if you're interested in all notifications, don't pass a filter/predicate. // in this case, we filter on events by time, and only notify if the new event is > 1 second from // the last event. _input.Subscribe(new FilterableChangeObserver <DigitalInputPortEventArgs, DateTime>( e => { Console.WriteLine($"Observer Observing the Observable, Observably speaking, Time: {e.New.Millisecond}, Value: {e.Value}"); }, // Optional filter paramter, showing a 1 second filter, i.e., only notify // if the new event is > 1 second from last. f => { return(f.Delta > new TimeSpan(0, 0, 0, 0, 1000)); })); Console.WriteLine("Got here 3."); }
/// <summary> /// Instantiates an Mcp23008 on the specified I2C bus, with the specified /// peripheral address. /// </summary> /// <param name="i2cBus"></param> /// <param name="address"></param> public Mcp23x08(II2cBus i2cBus, byte address = 0x20, IDigitalInputPort interruptPort = null) : // use the internal constructor that takes an IMcpDeviceComms this(new I2cMcpDeviceComms(i2cBus, address), interruptPort) { // nothing goes here }
/// <summary> /// Create a new HYSRF05 object and hook up the interrupt handler /// HSSRF05 must be running the default 4/5 pin mode /// 3 pin mode is not supported on Meadow /// </summary> /// <param name="triggerPort"></param> /// <param name="echoPort"></param> public Hysrf05(IDigitalOutputPort triggerPort, IDigitalInputPort echoPort) { this.triggerPort = triggerPort; this.echoPort = echoPort; this.echoPort.Changed += OnEchoPortChanged; }
void Initialize() { Console.WriteLine("Initialize hardware..."); portLeft = Device.CreateDigitalInputPort(Device.Pins.D02); portRight = Device.CreateDigitalInputPort(Device.Pins.D03); portDown = Device.CreateDigitalInputPort(Device.Pins.D04); portReset = Device.CreateDigitalInputPort(Device.Pins.D05); speaker = new PiezoSpeaker(Device.CreatePwmPort(Device.Pins.D06)); var config = new SpiClockConfiguration( speed: new Frequency(6000, 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.D10, dcPin: Device.Pins.D01, resetPin: Device.Pins.D00, width: 240, height: 240); Console.WriteLine("Create graphics library"); graphics = new MicroGraphics(display); graphics.CurrentFont = new Font12x16(); }
/// <summary> /// Create a new HYSRF05 object and hook up the interrupt handler /// HSSRF05 must be running the default 4/5 pin mode /// 3 pin mode is not supported on Meadow /// </summary> /// <param name="triggerPort"></param> /// <param name="echoPort"></param> public HYSRF05(IDigitalOutputPort triggerPort, IDigitalInputPort echoPort) { _triggerPort = triggerPort; _echoPort = echoPort; _echoPort.Changed += OnEchoPortChanged; }
void Initialize() { Console.WriteLine("Initialize hardware..."); portLeft = Device.CreateDigitalInputPort(Device.Pins.D13); portRight = Device.CreateDigitalInputPort(Device.Pins.D11); portDown = Device.CreateDigitalInputPort(Device.Pins.D12); portReset = Device.CreateDigitalInputPort(Device.Pins.D07); speaker = new PiezoSpeaker(Device.CreatePwmPort(Device.Pins.D05)); var config = new SpiClockConfiguration( speed: new Frequency(12000, Frequency.UnitType.Kilohertz), mode: SpiClockConfiguration.Mode.Mode0); var spiBus = Device.CreateSpiBus( clock: Device.Pins.SCK, copi: Device.Pins.MOSI, cipo: Device.Pins.MISO, config: config); var display = new Ssd1309 ( device: Device, spiBus: spiBus, chipSelectPin: Device.Pins.D02, dcPin: Device.Pins.D01, resetPin: Device.Pins.D00 ); graphics = new MicroGraphics(display); graphics.CurrentFont = new Font4x8(); }
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); var config = new SpiClockConfiguration(3000, SpiClockConfiguration.Mode.Mode3); var spiBus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config); button = Device.CreateDigitalInputPort(Device.Pins.D12, InterruptMode.EdgeRising, ResistorMode.Disabled); button.Changed += Button_Changed; //display display = new St7789( device: Device, spiBus: spiBus, chipSelectPin: Device.Pins.D02, dcPin: Device.Pins.D01, resetPin: Device.Pins.D00, width: 240, height: 240); graphics = new GraphicsLibrary(display); graphics.CurrentFont = new Font12x20(); sensor = new Bmp180(Device.CreateI2cBus()); sensor.Updated += Sensor_Updated; sensor.StartUpdating(); }
void Initialize() { Console.WriteLine("Initializing hardware..."); //==== create an input port on D02. input = Device.CreateDigitalInputPort( Device.Pins.D02, InterruptMode.EdgeBoth, ResistorMode.InternalPullDown, 20, 10); //==== Classic .NET Events input.Changed += (object sender, DigitalPortResult result) => { Console.WriteLine($"Old school event raised; Time: {result.New.Time}, Value: {result.New.State}"); }; //===== Filterable Observer // this illustrates using a FilterableObserver. Note that the filter is an optional // parameter, if you're interested in all notifications, don't pass a filter/predicate. // in this case, we filter on events by time, and only notify if the new event is > 1 second from // the last event. var observer = IDigitalInputPort.CreateObserver( handler: result => { Console.WriteLine($"Observer filter satisfied, time: {result.New.Time.ToShortTimeString()}"); }, // Optional filter paramter, showing a 1 second filter, i.e., only notify // if the new event is > 1 second from last time it was notified. filter: result => { if (result.Old is { } old) // C# 8 null pattern matching for not null { return((result.New.Time - old.Time) > TimeSpan.FromSeconds(1)); }
public HCSR_04(IDigitalInputPort e, IDigitalOutputPort t, Unit measureUnit) { echo = e; trigger = t; //echo.Changed += EchoChanged; MeasureUnit = measureUnit; }
void Initialize() { Console.WriteLine("Initialize hardware..."); portLeft = Device.CreateDigitalInputPort(Device.Pins.D13); portRight = Device.CreateDigitalInputPort(Device.Pins.D11); portDown = Device.CreateDigitalInputPort(Device.Pins.D12); portReset = Device.CreateDigitalInputPort(Device.Pins.D07); speaker = new PiezoSpeaker(Device.CreatePwmPort(Device.Pins.D05)); var config = new SpiClockConfiguration(12000, SpiClockConfiguration.Mode.Mode0); var bus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config); display = new Ssd1309 ( device: Device, spiBus: bus, chipSelectPin: Device.Pins.D02, dcPin: Device.Pins.D01, resetPin: Device.Pins.D00 ); graphics = new GraphicsLibrary(display); graphics.CurrentFont = new Font4x8(); }
private void Initialize() { Console.WriteLine("Initialize hardware..."); _pirSensor = Device.CreateDigitalInputPort(Device.Pins.D02, InterruptMode.EdgeBoth, ResistorMode.Disabled, 20d); _pirSensor.Changed += OnSensorChanged; }
void Initialize() { Console.WriteLine("Initialize hardware..."); portLeft = Device.CreateDigitalInputPort(Device.Pins.D02); portRight = Device.CreateDigitalInputPort(Device.Pins.D03); portDown = Device.CreateDigitalInputPort(Device.Pins.D04); portReset = Device.CreateDigitalInputPort(Device.Pins.D05); speaker = new PiezoSpeaker(Device.CreatePwmPort(Device.Pins.D06)); var config = new SpiClockConfiguration(6000, SpiClockConfiguration.Mode.Mode3); var spiBus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config); Console.WriteLine("Create display driver instance"); display = new St7789(device: Device, spiBus: spiBus, chipSelectPin: Device.Pins.D10, dcPin: Device.Pins.D01, resetPin: Device.Pins.D00, width: 240, height: 240); Console.WriteLine("Create graphics library"); graphics = new GraphicsLibrary(display); graphics.CurrentFont = new Font12x16(); }
void Initialize() { portLeft = Device.CreateDigitalInputPort(Device.Pins.D12); portUp = Device.CreateDigitalInputPort(Device.Pins.D13); portRight = Device.CreateDigitalInputPort(Device.Pins.D07); portDown = Device.CreateDigitalInputPort(Device.Pins.D11); 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 Ssd1309 ( device: Device, spiBus: spiBus, chipSelectPin: Device.Pins.D02, dcPin: Device.Pins.D01, resetPin: Device.Pins.D00 ); graphics = new MicroGraphics(display); graphics.CurrentFont = new Font4x8(); graphics.Rotation = RotationType._270Degrees; }
/// <summary> /// Create a new Ds3231 object using the default parameters for the component. /// </summary> /// <param name="address">Address of the DS3231 (default = 0x68).</param> /// <param name="speed">Speed of the I2C bus (default = 100 KHz).</param> /// <param name="i2cBus">The I2C Bus the peripheral is connected to</param> /// <param name="interruptPort">Digital port connected to the alarm interrupt pin on the RTC.</param> public Ds3231( II2cBus i2cBus, IDigitalInputPort interruptPort = null, byte address = 0x68) : base(new I2cPeripheral(i2cBus, address), interruptPort) { }
public OLED128x32Wing(II2cBus i2cBus, IDigitalInputPort portA, IDigitalInputPort portB, IDigitalInputPort portC) { Display = new Ssd1306(i2cBus, 0x3C, Ssd1306.DisplayType.OLED128x32); ButtonA = new PushButton(portA, ResistorMode.PullUp); ButtonB = new PushButton(portB); // has physical resistor ButtonC = new PushButton(portC, ResistorMode.PullUp); }
public Hx711(IDigitalOutputPort sck, IDigitalInputPort dout) { this.sck = sck; this.dout = dout; CalculateRegisterValues(sck.Pin, dout.Pin); Start(); }
/// <summary> /// Instantiate a new RotaryEncoder on the specified ports /// </summary> /// <param name="aPhasePort"></param> /// <param name="bPhasePort"></param> public RotaryEncoder(IDigitalInputPort aPhasePort, IDigitalInputPort bPhasePort) { APhasePort = aPhasePort; BPhasePort = bPhasePort; APhasePort.Changed += PhaseAPinChanged; BPhasePort.Changed += PhaseBPinChanged; }
public OLED128x32Wing(II2cBus i2cBus, IDigitalInputPort portA, IDigitalInputPort portB, IDigitalInputPort portC) { Display = new Ssd1306(i2cBus, 0x3C, Ssd1306.DisplayType.OLED128x32); Display.IgnoreOutOfBoundsPixels = true; ButtonA = new PushButton(portA); ButtonB = new PushButton(portB); ButtonC = new PushButton(portC); }
/// <summary> /// Creates an instance of the NAU7802 Driver class /// </summary> /// <param name="bus"></param> public Hx711(IIODevice device, IPin sck, IPin dout) { this.sck = device.CreateDigitalOutputPort(sck); this.dout = device.CreateDigitalInputPort(dout); createdPorts = true; // we need to dispose what we create CalculateRegisterValues(sck, dout); Start(); }
/// <summary> /// Initializes a new instance of the SoundGenerator class /// </summary> /// <param name="inputPort1">First sound-level input port</param> /// <param name="inputPort2">Second sound-level input port</param> /// <param name="pwmPort">PWM port used to drive the speaker</param> public SoundGenerator(IDigitalInputPort inputPort1, IDigitalInputPort inputPort2, IPwmPort pwmPort) { this.volumeIn1 = inputPort1; this.volumeIn2 = inputPort2; this.speakerPWM = pwmPort; this.speaker = new PiezoSpeaker(this.speakerPWM); this.PlayInitialSound(); }
public ButtonEventsApp() { _input = Device.CreateDigitalInputPort( Device.Pins.D00, InterruptMode.EdgeBoth, ResistorMode.PullDown, debounceDuration: 20); _input.Changed += Input_Changed; Console.WriteLine("App initialized."); }
/// <summary> /// Create a new MAG3110 object using the default parameters for the component. /// </summary> /// <param name="address">Address of the DS3231 (default = 0x68).</param> /// <param name="speed">Speed of the I2C bus (default = 100 KHz).</param> /// <param name="interruptPort">Digital port connected to the alarm interrupt pin on the RTC.</param> // TODO: revisit; `DigitalPin.Empty`? public DS3231(IDigitalInputPort interruptPort, byte address = 0x68, ushort speed = 100) { _ds323x = new I2cBus(address, speed); // TODO: i changed this from GPIO_NONE // samples will need to pass null if (interruptPort != null) { InterruptPin = interruptPort; } }
public void ConfigurePeripherals() { IDigitalInputPort interruptPort = Device.CreateDigitalInputPort( Device.Pins.D00, InterruptMode.EdgeRising); // create a new mcp with all the address pins pulled low for // an address of 0x20/32 _mcp = new Mcp23x08(Device.CreateI2cBus(), false, false, false, interruptPort); }
/// <summary> /// Create a new Parallax PIR object connected to a interrupt port. /// </summary> /// <param name="digitalInputPort"></param> public Hcsens0040(IDigitalInputPort digitalInputPort) { if (digitalInputPort != null) { _digitalInputPort = digitalInputPort; _digitalInputPort.Changed += DigitalInputPortChanged; } else { throw new Exception("Invalid pin for the PIR interrupts."); } }
/// <summary> /// Main constructor /// </summary> /// <param name="leftForwardPwm">PWM port responsible for left motor moving forward</param> /// <param name="leftBackPwm">PWM port responsible for left motor moving backward</param> /// <param name="rightForwardPwm">PWM port responsible for right motor moving forward</param> /// <param name="rightBackPwm">PWM port responsible for right motor moving backward</param> /// <param name="gearPwm">PWM port responsible for controling gear changing servo</param> public MotorController(IPwmPort rightForwardPwm, IPwmPort rightBackPwm, IPwmPort leftForwardPwm, IPwmPort leftBackPwm, IPwmPort gearPwm, IDigitalInputPort leftCounterPort, IDigitalInputPort righCounterPort, BNO055 posSens, CameraGimbal gimb, Action clQueue) { quarterCircle = fullCircle / 4; halfCircle = fullCircle / 2; positionSensor = posSens; gimbal = gimb; clearQueue = clQueue; circumference = teethCount * chainPitch / magnetsCount; leftMotor = new Motor(leftForwardPwm, leftBackPwm); rightMotor = new Motor(rightForwardPwm, rightBackPwm); gearbox = new GearBox(gearPwm); rightCounter = new HallEffectCounter(righCounterPort); leftCounter = new HallEffectCounter(leftCounterPort); rightCounter.Name = Side.Right; leftCounter.Name = Side.Left; #if DEBUG rightCounter.RegisterForCount(CountChanged); leftCounter.RegisterForCount(CountChanged); #endif rightCounter.RegisterForLimitReached(MoveForwardStop); leftCounter.RegisterForLimitReached(MoveForwardStop); positionSensor.RegisterForHeadingChanged(HeadingChanged); moveForwardResetEventLeft = new AutoResetEvent(false); moveForwardResetEventRight = new AutoResetEvent(false); turnResetEvent = new AutoResetEvent(false); turnTokenSource = new CancellationTokenSource(); turnPid = new IdealPidController(); turnPid.ProportionalComponent = 1.8f; turnPid.IntegralComponent = 0.05f; turnPid.DerivativeComponent = 0.01f; turnPid.OutputMax = 50; turnPid.OutputMin = -50; stabilizePid = new IdealPidController(); stabilizePid.ProportionalComponent = 1.8f; stabilizePid.IntegralComponent = 0.05f; stabilizePid.DerivativeComponent = 0.01f; stabilizePid.OutputMax = stabilizeTurnRate; stabilizePid.OutputMin = -stabilizeTurnRate; }
/// <summary> /// Create a new Ds3231 object using the default parameters for the component. /// </summary> /// <param name="address">Address of the DS3231 (default = 0x68).</param> /// <param name="speed">Speed of the I2C bus (default = 100 KHz).</param> /// <param name="interruptPort">Digital port connected to the alarm interrupt pin on the RTC.</param> public Ds3231(II2cBus i2cBus, IDigitalInputPort interruptPort, byte address = 0x68, ushort speed = 100) { _ds323x = new I2cPeripheral(i2cBus, address); // samples will need to pass null if (interruptPort != null) { _interruptPort = interruptPort; _interruptPort.Changed += InterruptPort_Changed; } }
protected void MainLoop() { Console.WriteLine("Initialize a PushButton and its events handler on pin D03..."); inputBtn = Device.CreateDigitalInputPort(Device.Pins.D03, InterruptMode.EdgeBoth, ResistorMode.PullUp, 50); // TODO: Some reason the events PressStarted / Ended and also the inputBtn.Changed seems not to work anymore.... // but the "Console.WriteLine($"InputBtn.State = {inputBtn.State}"); " in the loop seems to work !. // STRANGE.... var pushButton = new PushButton(inputBtn); pushButton.PressStarted += PushButton_PressStarted; pushButton.PressEnded += PushButton_PressEnded; // add an event handler inputBtn.Changed += (s, o) => { Console.WriteLine("Event Changed => ToggleLed."); //ToggleLed(led); }; Console.WriteLine("Starting MainLoop..."); while (true) { Console.WriteLine($"InputBtn.State = {inputBtn.State}"); Console.WriteLine($"inputD04.State = {inputD04.State}"); DisplayText("Blink RED"); Blink(Color.Red); Console.WriteLine($"InputBtn.State = {inputBtn.State}"); Console.WriteLine($"inputD04.State = {inputD04.State}"); DisplayText("Blink GREEN"); Blink(Color.Green); Console.WriteLine($"InputBtn.State = {inputBtn.State}"); Console.WriteLine($"inputD04.State = {inputD04.State}"); DisplayText("Blink BLUE"); Blink(Color.Blue); Console.WriteLine($"InputBtn.State = {inputBtn.State}"); Console.WriteLine($"inputD04.State = {inputD04.State}"); } }
public MeadowApp() { try { hour = new PushButton(Device, Device.Pins.D15); hour.Clicked += HourClicked; Console.WriteLine("subscribe test"); //minute = new PushButton(Device, Device.Pins.D12); //minute.Clicked += MinuteClicked; this.inputPort = Device.CreateDigitalInputPort(Device.Pins.D12, interruptMode: InterruptMode.EdgeBoth, debounceDuration: 100); //this.inputPort.Changed += (object sender, DigitalInputPortEventArgs e) => //{ // //Console.WriteLine("Change detected"); // Console.WriteLine($"Old school event raised; Time: {e.New.Millisecond}, Value: {e.Value}"); //}; this.inputPort.Subscribe(new FilterableChangeObserver <DigitalInputPortEventArgs, DateTime>( e => { if (!e.Value) { Console.WriteLine($"Event observed at {e.New.Millisecond}, Value: {e.Value}\r\n"); this.MinuteClicked(null, null); } }, f => { return(true); // return (f.Delta > new TimeSpan(0, 0, 0, 0, 100)); })); display = new CharacterDisplay ( device: Device, pinRS: Device.Pins.D10, pinE: Device.Pins.D09, pinD4: Device.Pins.D08, pinD5: Device.Pins.D07, pinD6: Device.Pins.D06, pinD7: Device.Pins.D05 ); Device.SetClock(new DateTime(2020, 07, 24, 11, 00, 00)); CharacterDisplayClock(); } catch (Exception e) { Console.WriteLine($"Exception: {e.ToString()}"); } }
/// <summary> /// Create a new Parallax PIR object connected to a interrupt port. /// </summary> /// <param name="digitalInputPort"></param> public ParallaxPir(IDigitalInputPort digitalInputPort) { //TODO: I changed this from Pins.GPIO_NONE to null if (digitalInputPort != null) { _digitalInputPort = digitalInputPort; _digitalInputPort.Changed += DigitalInputPortChanged; } else { throw new Exception("Invalid pin for the PIR interrupts."); } }