Signal Capture
The SignalCapture class monitors a pin and records any changes (high-low or low-high transitions) of the pin into an array. It is a digital waveform recorder. Each array element is the number of microseconds between each signal change.
When calling Read, it blocks other code from executing until it either fills the input buffer or it has captured the number of transitions specified by the count argument. If your signal is shorter than that, the call will never return. Make sure to request only what you plan to capture.
The following sample code captures the signal generated by pressing BTN1 on the FEZ. It will attempt to capture 100 transitions, waiting no more than 10 seconds. It will also enable the pull-up resistor on the pin. It will return the initial state of the pin when it started capturing and how many transitions it captured. Note that the signal capture may record button bounces, resulting in a number of transitions in rapid succession.
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Signals;
using GHIElectronics.TinyCLR.Pins;
using System;
using System.Threading;
public static class Program {
public static void Main() {
var cap = new SignalCapture(FEZ.GpioPin.Btn1);
var buffer = new TimeSpan[100];
cap.DisableInterrupts = false;
cap.Timeout = TimeSpan.FromSeconds(10);
cap.DriveMode = GpioPinDriveMode.InputPullUp;
while (true) {
var count = cap.Read(out var init, buffer);
Thread.Sleep(100);
}
}
}