private static readonly object m_ThreadLock = new object(); // lock object to start/stop scanning thread #endregion /// <summary> /// Create a new instance of Driver2x74HC595 /// </summary> /// <param name="DsPin">Ds Pin Number</param> /// <param name="STcpPin">STcp Pin Number</param> /// <param name="SHcpPin">SHcp Pin Number</param> public Driver2x74HC595(int DsPin, int STcpPin, int SHcpPin) { m_IsScanActive = false; var gpio = GpioController.GetDefault(); // setup the pins PinDS = gpio.OpenPin(DsPin); PinDS.SetDriveMode(GpioPinDriveMode.Output); PinSTCP = gpio.OpenPin(STcpPin); PinSTCP.SetDriveMode(GpioPinDriveMode.Output); PinSHCP = gpio.OpenPin(SHcpPin); PinSHCP.SetDriveMode(GpioPinDriveMode.Output); // initialize the pins to low PinDS.Write(GpioPinValue.Low); PinSTCP.Write(GpioPinValue.Low); PinSHCP.Write(GpioPinValue.Low); // create scan thread m_WorkerThread = new BackgroundWorker { WorkerSupportsCancellation = true }; m_WorkerThread.DoWork += (sender, args) => { while (!m_WorkerThread.CancellationPending) { PresentMatrix(); // scan matrix to LED } }; }
// Write one byte of data private void WriteData(byte rowData8Bit) { for (int i = 8; i >= 1; i--) { PinDS.Write((rowData8Bit & 0x80) > 0 ? GpioPinValue.High : GpioPinValue.Low); rowData8Bit <<= 1; PulseSHCP(); } }