public void On() { if (!_outputPin.Read()) { _outputPin.Write(true); } }
public Display() { cs = Pi.Gpio[P1.Pin24]; // GPIO8 = Pin 24 cs.PinMode = GpioPinDriveMode.Output; // use pin as ouptut pin cs.Write(false); res = Pi.Gpio[P1.Pin35]; // GPI19 = Pin 35 res.PinMode = GpioPinDriveMode.Output; // use pin as ouptut pin res.Write(true); Thread.Sleep(10); res.Write(false); Thread.Sleep(10); res.Write(true); dnc = Pi.Gpio[P1.Pin36]; // GPI16 = Pin 36 dnc.PinMode = GpioPinDriveMode.Output; // use pin as ouptut pin dnc.Write(false); I2CtoSPI spiDevice = new I2CtoSPI(0, 0); disp = new SSD1306(spiDevice, SSD1306.DisplayModel.Display128X64, SSD1306.VccSourceMode.Switching); bitmap = new Bitmap(128, 64); Graphics = Graphics.FromImage(bitmap); Clear(); }
protected override void makeStep() { pin.Write(true); //Console.Write(curr); //if(rev) Console.Write("<"); else Console.Write(">"); }
public void Update() { disp.LoadBitmap(bitmap, 0.5, 0, 0); dnc.Write(false); disp.SetAddressRange(); dnc.Write(true); disp.Render(); }
public void Forward() { WiringPi.SoftPwmWrite(enableA.BcmPinNumber, ENA1Pwm); WiringPi.SoftPwmWrite(enableB.BcmPinNumber, ENA2Pwm); motor1.Write(false); motor2.Write(true); motor3.Write(true); motor4.Write(false); }
public static void BeepSignal() { if (_initDone == false) { Init(); } _pulsePin.Write(true); Thread.Sleep(300); _pulsePin.Write(false); }
public void EnableBuzzer(int amount = 3, int howLong = 100, int interval = 200) { new Thread(() => { for (int i = 0; i < amount; i++) { buzzer.Write(GpioPinValue.High); Thread.Sleep(howLong); buzzer.Write(GpioPinValue.Low); Thread.Sleep(interval); } }).Start(); }
public void Init() { _res.PinMode = GpioPinDriveMode.Output; _dc.PinMode = GpioPinDriveMode.Output; _res.Write(GpioPinValue.Low); _res.Write(GpioPinValue.High); Write(Instruction.SetOperationMode(instructionSet: InstructionSet.Extended)); Write(Instruction.SetTemperatureCoefficient(0)); Write(Instruction.SetBiasSystem(4)); Write(Instruction.SetOperationMode(instructionSet: InstructionSet.Basic)); Write(Instruction.SetDisplayConfiguration(DisplayMode.Normal)); }
private void WriteRegister(byte regNum, byte dataByte, IGpioPin csPin) { csPin.Write(false); // 0x8x to specify 'write register value' var addressByte = (0x80 | regNum); //todo: Verify this. // first byte is address byte SendByte((byte)addressByte); // the rest are data bytes SendByte(dataByte); csPin.Write(true); }
public tm1637() { //Pi.Init<BootstrapWiringPi>(); /* clkPin = gpio.OpenPin(pinClock); * clkPin.SetDriveMode(GpioPinDriveMode.Output); * * dataPin = gpio.OpenPin(pinData); * dataPin.SetDriveMode(GpioPinDriveMode.Output);*/ Pi.Init <BootstrapWiringPi>(); clkPin = Pi.Gpio[BcmPin.Gpio23]; dataPin = Pi.Gpio[BcmPin.Gpio24]; // Configure the pin as an output clkPin.PinMode = GpioPinDriveMode.Output; dataPin.PinMode = GpioPinDriveMode.Output; clkPin.Write(GpioPinValue.Low); dataPin.Write(GpioPinValue.Low); //Init Display for (int i = 0; i < 4; i++) { this.digits[i] = 0x00; } //Set Brightness setBrightness(brightness); //Display blinks during Startup startupShow(); }
public LEDOUT(int pin) { Pi.Init <BootstrapWiringPi>(); ledPin = Pi.Gpio[pin]; ledPin.PinMode = GpioPinDriveMode.Output; ledPin.Write(false); }
public void Initialize() { if (IsInitialized) { throw new InvalidOperationException($"{nameof(WaterSystem)} is already initialized"); } Logger.LogTrace("Initializing.."); var waterControllerConfigs = new[] { new { Id = "B01", PinId = BcmPin.Gpio26, LitersPerSecond = 0.01 }, new { Id = "B02", PinId = BcmPin.Gpio20, LitersPerSecond = 0.01 }, new { Id = "B03", PinId = BcmPin.Gpio21, LitersPerSecond = 0.01 }, }; foreach (var config in waterControllerConfigs) { IGpioPin pin = GpioPinFactory.CreatePin(config.PinId); pin.Write(WaterController.PIN_OFF); IWaterController waterController = WaterControllerFactory.CreateWaterController(config.Id, pin, config.LitersPerSecond); IdToWaterController.Add(config.Id, waterController); } IsInitialized = true; Logger.LogInformation("Application initialized"); }
public DHT(IGpioPin datatPin, DHTSensorTypes sensor) { _logger.Information("Sensor setup..."); if (datatPin != null) { try { _dataPin = datatPin; _firstReading = true; _prevReading = DateTime.MinValue; _data = new UInt32[6]; _sensorType = sensor; //Init the data pin _dataPin.PinMode = GpioPinDriveMode.Output; _dataPin.Write(GpioPinValue.High); } catch (Exception ex) { _logger.Error(ex, "Error in DHT setup"); } } else { throw new ArgumentException("Parameter cannot be null.", "dataPin"); } }
public static void BlinkLed(IGpioPin led, int blinkTime = 500, int blinkAmount = 1, int blinkWaitTime = 100) { led.PinMode = GpioPinDriveMode.Output; Task.Run(async() => { for (var i = 0; i < blinkAmount; i++) { led.Write(GpioPinValue.Low); await Task.Delay(blinkTime).ConfigureAwait(false); led.Write(GpioPinValue.High); if (blinkAmount > 1) { await Task.Delay(blinkWaitTime).ConfigureAwait(false); } } }); }
public void Initialize() { // Initialize abstraction implementation. Pi.Init <BootstrapWiringPi>(); _ledPin = Pi.Gpio[BcmPin.Gpio22]; _ledPin.PinMode = GpioPinDriveMode.Output; _ledPin.Write(GpioPinValue.High); var isOn = false; for (var i = 0; i < 1000; i++) { isOn = !isOn; _ledPin.Write(isOn); System.Threading.Thread.Sleep(100); } }
private byte[] ReadRegisters(byte regNumStart, int numRegisters, IGpioPin csPin) { var returnByte = new List <byte>(); csPin.Write(false); SendByte(regNumStart); for (var i = 0; i < numRegisters; i++) { var data = RecvByte(); returnByte.Add(data); } csPin.Write(true); return(returnByte.ToArray()); }
static void MatrixOut(int[] matrix, TimeSpan timeSpan, IGpioPin latchPin, IGpioPin dataPin, IGpioPin clockPin) { var startTime = DateTime.UtcNow; while (DateTime.UtcNow - startTime < timeSpan) { var column = 0x80; for (var i = 0; i < 8; i++) { latchPin.Write(false); ShiftOut(dataPin, clockPin, false, matrix[i]); // first shift data of line information to the first stage 74HC959 ShiftOut(dataPin, clockPin, false, ~column); //then shift data of column information to the second stage 74HC959 latchPin.Write(true); //Output data of two stage 74HC595 at the same column >>= 1; //display the next columndelay(1); Thread.Sleep(2); //Try and keep the column LEDs on a short time to make them brighter. } } }
static void ShiftOut(IGpioPin dPin, IGpioPin cPin, bool lsbFirst, int val) { int i; for (i = 0; i < 8; i++) { cPin.Write(false); if (lsbFirst) { dPin.Write((0x01 & (val >> i)) == 0x01); } else { dPin.Write((0x80 & (val << i)) == 0x80); } cPin.Write(true); } }
public static void InvertLedSignal() { if (_initDone == false) { Init(); } var isOn = _blinkingPin.Read(); if (isOn) { _blinkingPin.Write(false); } else { _blinkingPin.Write(true); } }
private void UpdateLineStatus(IGpioPin line, bool newStatus) { var oldStatus = line.Read(); // on when false , off when true if (oldStatus == newStatus) { line.Write(!newStatus); } }
/// <summary> /// Write the given value to the given pin. /// </summary> /// <param name="pin">The pin to set.</param> /// <param name="state">The new state of the pin.</param> public static void WriteDigital(IGpioPin gpioPin, bool state) { if (gpioPin.PinMode != GpioPinDriveMode.Output) { gpioPin.PinMode = GpioPinDriveMode.Output; } gpioPin.Write(state ? GpioPinValue.High : GpioPinValue.Low); }
private void SendByte(byte @byte) { for (var i = 0; i < 8; i++) { ClkPin.Write(true); if ((@byte & 0x80) > 0) { MosiPin.Write(true); } else { MosiPin.Write(false); } @byte = unchecked ((Byte)(@byte << 1)); ClkPin.Write(false); } }
/// <summary> /// Constructor. /// </summary> /// <param name="enablePin">Enablepin, a soft pwm driver will be connected to the pin.</param> /// <param name="in1Pin">In1 pin.</param> /// <param name="in2Pin">In2 pin.</param> public L293d(int enablePin, int in1Pin, int in2Pin) { _enablePin = new SoftPwmDriver(enablePin); _in1Pin = GenericGpioController.GetDefault().OpenPin(in1Pin); _in1Pin.SetDriveMode(GpioPinDriveMode.Output); _in2Pin = GenericGpioController.GetDefault().OpenPin(in2Pin); _in2Pin.SetDriveMode(GpioPinDriveMode.Output); _in1Pin.Write(GpioPinValue.Low); _in2Pin.Write(GpioPinValue.Low); }
public void ClearAllLines() { //_line1.InputPullMode = GpioPinResistorPullMode.PullUp; //_line2.InputPullMode = GpioPinResistorPullMode.PullUp; //_line3.InputPullMode = GpioPinResistorPullMode.PullUp; //_line4.InputPullMode = GpioPinResistorPullMode.PullUp; _line1.Write(GpioPinValue.High); // by default high made relay off _line2.Write(GpioPinValue.High); _line3.Write(GpioPinValue.High); _line4.Write(GpioPinValue.High); }
private UltrasonicReadEventArgs RetrieveSensorData() { try { // Send trigger pulse _triggerPin.Write(GpioPinValue.Low); Pi.Timing.SleepMicroseconds(2); _triggerPin.Write(GpioPinValue.High); Pi.Timing.SleepMicroseconds(12); _triggerPin.Write(GpioPinValue.Low); if (!_echoPin.WaitForValue(GpioPinValue.High, 50)) { throw new TimeoutException(); } _measurementTimer.Start(); if (!_echoPin.WaitForValue(GpioPinValue.Low, 50)) { throw new TimeoutException(); } _measurementTimer.Stop(); var elapsedTime = _measurementTimer.ElapsedMicroseconds; _measurementTimer.Reset(); var distance = elapsedTime / 58.0; if (elapsedTime > NoObstaclePulseMicroseconds) { distance = NoObstacleDistance; } return(new UltrasonicReadEventArgs(distance)); } catch { return(UltrasonicReadEventArgs.CreateInvalidReading()); } }
/// <summary> /// Constructor. /// </summary> /// <param name="trigPin">pin number of the trig of the sensor.</param> /// <param name="echoPin">pint number of the echo of the sensor.</param> public UltraSonicSensor(int trigPin, int echoPin) { _trigPin = GenericGpioController.GetDefault().OpenPin(trigPin); _trigPin.SetDriveMode(GpioPinDriveMode.Output); _echoPin = GenericGpioController.GetDefault().OpenPin(echoPin); _echoPin.SetDriveMode(GpioPinDriveMode.Input); _trigPin.Write(GpioPinValue.Low); _echoPin.ValueChanged += _echoPin_ValueChanged; _timer = new Stopwatch(); }
public void OFF() { isOn = false; if (isPWM = true) { isPWM = false; WiringPi.SoftPwmStop(pin); } else { ledPin.Write(false); } }
public DHT(BcmPin datatPin, DHTSensorTypes sensor) { if (datatPin != 0) { _dataPin = Pi.Gpio[datatPin]; _firstReading = true; _prevReading = DateTime.MinValue; _data = new UInt32[6]; _sensorType = sensor; //Init the data pin _dataPin.PinMode = GpioPinDriveMode.Output; _dataPin.Write(GpioPinValue.High); } else { throw new ArgumentException("Parameter cannot be null.", "dataPin"); } }
public TempReader(ILogger <TempReader> logger) { _logger = logger; CsPin1 = Pi.Gpio[7]; CsPin2 = Pi.Gpio[8]; MisoPin = Pi.Gpio[9]; MosiPin = Pi.Gpio[10]; ClkPin = Pi.Gpio[11]; TempReadHeartbeat = Pi.Gpio[5]; CsPin1.PinMode = GpioPinDriveMode.Output; CsPin2.PinMode = GpioPinDriveMode.Output; MisoPin.PinMode = GpioPinDriveMode.Input; MosiPin.PinMode = GpioPinDriveMode.Output; ClkPin.PinMode = GpioPinDriveMode.Output; TempReadHeartbeat.PinMode = GpioPinDriveMode.Output; CsPin1.Write(true); CsPin2.Write(true); }
/// <summary> /// Let's say that's M/S /// </summary> /// <param name="speed" range=0-100></param> public void SetSpeed(int speed) { Forward = speed > 0; // set as appropriate Reverse = !Forward; kFactor = (MaxDuty - MinDuty) / 100.0; Speed = speed; if (Forward) { Speed = Math.Min(Speed, 100); } else { Speed = Math.Max(Speed, -100); } var pwmDuty = MinDuty + (Math.Abs(Speed) * kFactor); DutyCycle = (uint)Math.Min(MaxDuty, pwmDuty); Forward = speed > 0; // set as appropriate Reverse = !Forward; if (speed == 0) { Forward = false; Reverse = false; } if (!Testing) { PinPwm.PwmRegister = (int)DutyCycle; PinFwd.Write(Forward); PinRev.Write(Reverse); } }
public Led(IGpioController controller, GpioEnum gpio, bool initialValue = false) { Pin = controller.OpenPin(gpio); Pin.Write(initialValue ? GpioPinValueEnum.Low : GpioPinValueEnum.High); Pin.SetDriveMode(GpioPinDriveModeEnum.Output); }
private bool Read() { var now = DateTime.UtcNow; if (!_firstReading && ((now - _prevReading).TotalMilliseconds < 2000)) { return(false); } _firstReading = false; _prevReading = now;; _data[0] = _data[1] = _data[2] = _data[3] = _data[4] = 0; _dataPin.PinMode = GpioPinDriveMode.Output; _dataPin.Write(GpioPinValue.High); Thread.Sleep(250); _dataPin.Write(GpioPinValue.Low); Thread.Sleep(20); //TIME CRITICAL ############### _dataPin.Write(GpioPinValue.High); //=> DELAY OF 40 microseconds needed here WaitMicroseconds(40); _dataPin.PinMode = GpioPinDriveMode.Input; //Delay of 10 microseconds needed here WaitMicroseconds(10); if (ExpectPulse(GpioPinValue.Low) == 0) { return(false); } if (ExpectPulse(GpioPinValue.High) == 0) { return(false); } // Now read the 40 bits sent by the sensor. Each bit is sent as a 50 // microsecond low pulse followed by a variable length high pulse. If the // high pulse is ~28 microseconds then it's a 0 and if it's ~70 microseconds // then it's a 1. We measure the cycle count of the initial 50us low pulse // and use that to compare to the cycle count of the high pulse to determine // if the bit is a 0 (high state cycle count < low state cycle count), or a // 1 (high state cycle count > low state cycle count). for (int i = 0; i < 40; ++i) { UInt32 lowCycles = ExpectPulse(GpioPinValue.Low); if (lowCycles == 0) { return(false); } UInt32 highCycles = ExpectPulse(GpioPinValue.High); if (highCycles == 0) { return(false); } _data[i / 8] <<= 1; // Now compare the low and high cycle times to see if the bit is a 0 or 1. if (highCycles > lowCycles) { // High cycles are greater than 50us low cycle count, must be a 1. _data[i / 8] |= 1; } // Else high cycles are less than (or equal to, a weird case) the 50us low // cycle count so this must be a zero. Nothing needs to be changed in the // stored data. } //TIME CRITICAL_END ############# // Check we read 40 bits and that the checksum matches. if (_data[4] == ((_data[0] + _data[1] + _data[2] + _data[3]) & 0xFF)) { return(true); } else { //Checksum failure! return(false); } }