public BitBotController(PCA9685Controller pcaController, PwmChannel buzzer, AdcChannel leftLineSensor, AdcChannel rightLineSensor, GpioPin distanceTrigPin, GpioPin distanceEchoPin, GpioPin frontSensorEnable, AdcChannel frontSensorValue, GpioPin colorLedPin) { this.pcaController = pcaController; this.buzzer = buzzer; this.pcaController.SetFrequency(50); this.frontSensorEnable = frontSensorEnable; this.frontSensorValue = frontSensorValue; this.leftLineSensor = leftLineSensor; this.rightLineSensor = rightLineSensor; this.pulseFeedback = new PulseFeedback(distanceTrigPin, distanceEchoPin, PulseFeedbackMode.EchoDuration) { DisableInterrupts = false, Timeout = TimeSpan.FromSeconds(1), PulseLength = TimeSpan.FromTicks(100), PulseValue = GpioPinValue.High, EchoValue = GpioPinValue.High, }; this.frontSensorEnable.SetDriveMode(GpioPinDriveMode.Output); this.frontSensorEnable.Write(GpioPinValue.High); var sg = new SignalGenerator(colorLedPin); this.ws2812 = new WS2812Controller(sg, 3); }
/// <summary> /// Constructor of HC-SR04 /// </summary> /// <param name="triggerPin">pin connected to trigger pin</param> /// <param name="echoPin">pin connected to echo pin</param> public Hcsr04(int triggerPin, int echoPin) { //_pulse = new GpioPulseReaderWriter(GpioPulseReaderWriter.Mode.EchoDuration, true, 10, triggerPin, true, echoPin); _pulse = new PulseFeedback(triggerPin, echoPin, PulseFeedbackMode.EchoDuration) { PulseLength = TimeSpan.FromTicks(10 * 10) }; }
/// <summary> /// Constructor of HC-SR04 /// </summary> /// <param name="signalPin">pin connected to trigger and echo pin</param> public UltrasonicRanger(int signalPin) { //_pulse = new GpioPulseReaderWriter( // GpioPulseReaderWriter.Mode.EchoDuration, true, 10, signalPin); // Note: // 1 tick = 100ns // 100 ticks = 10us _pulse = new PulseFeedback(signalPin, PulseFeedbackMode.EchoDuration) { PulseLength = TimeSpan.FromTicks(100) }; }
/// <summary> /// Reads the value of the pad. /// </summary> /// <param name="pad">The <see cref="Pad" /> to check.</param> /// <returns>The value of the pad.</returns> public static long RawRead(Pad pad) { if (_pins[0] == null) { _pins[0] = new PulseFeedback(PulseFeedback.Mode.DrainDuration, true, 10, (Cpu.Pin) 32); _pins[1] = new PulseFeedback(PulseFeedback.Mode.DrainDuration, true, 10, (Cpu.Pin) 33); _pins[2] = new PulseFeedback(PulseFeedback.Mode.DrainDuration, true, 10, (Cpu.Pin) 34); } switch (pad) { case Pad.Left: return(_pins[0].Read()); case Pad.Middle: return(_pins[1].Read()); case Pad.Right: return(_pins[2].Read()); default: return(0); } }
static void TestTouchPads() { var pulse = new PulseFeedback(GpioController.GetDefault().OpenPin(FEZBit.GpioPin.EdgeP0), PulseFeedbackMode.DrainDuration) { DisableInterrupts = true, Timeout = TimeSpan.FromSeconds(1), PulseLength = TimeSpan.FromMilliseconds(1), PulseValue = GpioPinValue.High, //EchoPinValue = GpioPinValue.High, //PulsePinDriveMode = GpioPinDriveMode.Input, //EchoPinDriveMode = GpioPinDriveMode.Input }; while (true) { var d = pulse.Trigger(); Thread.Sleep(250); } }
public TinyBitController(I2cController i2cController, PwmChannel buzzer, AdcChannel voiceSensor, GpioPin leftLineSensor, GpioPin rightLineSensor, GpioPin distanceTrigger, GpioPin distanceEcho, int colorLedPin) { this.i2c = i2cController.GetDevice(new I2cConnectionSettings(0x01, 400_000)); this.buzzer = buzzer; this.voiceSensor = voiceSensor; this.leftLineSensor = leftLineSensor; this.leftLineSensor.SetDriveMode(GpioPinDriveMode.Input); this.rightLineSensor = rightLineSensor; this.rightLineSensor.SetDriveMode(GpioPinDriveMode.Input); this.ws2812 = new WS2812(GpioController.GetDefault().OpenPin(colorLedPin), 2); this.distanceEcho = distanceEcho; this.distanceTrigger = distanceTrigger; this.pulseFeedback = new PulseFeedback(distanceTrigger, this.distanceEcho, PulseFeedbackMode.EchoDuration) { DisableInterrupts = false, Timeout = TimeSpan.FromSeconds(1), PulseLength = TimeSpan.FromTicks(100), PulseValue = GpioPinValue.High, EchoValue = GpioPinValue.High, }; }
/// <summary> /// Reads the value of the pad. /// </summary> /// <param name="pad">The <see cref="Pad" /> to check.</param> /// <returns>The value of the pad.</returns> public static long RawRead(Pad pad) { if (_pins[0] == null) { _pins[0] = new PulseFeedback(PulseFeedback.Mode.DrainDuration, true, 10, (Cpu.Pin)32); _pins[1] = new PulseFeedback(PulseFeedback.Mode.DrainDuration, true, 10, (Cpu.Pin)33); _pins[2] = new PulseFeedback(PulseFeedback.Mode.DrainDuration, true, 10, (Cpu.Pin)34); } switch (pad) { case Pad.Left: return _pins[0].Read(); case Pad.Middle: return _pins[1].Read(); case Pad.Right: return _pins[2].Read(); default: return 0; } }