public void SpiTest() { using (SpiDevice spi = new SoftwareSpi(clk: 6, miso: 23, mosi: 5, cs: 24)) { // do stuff over SPI } }
public RgbXmasTree(GpioController gpioController, int clockFrequency = 500000) { var settings = new SpiConnectionSettings(0) { ClockFrequency = clockFrequency }; spi = new SoftwareSpi(25, -1, 12, gpioController: gpioController, settings: settings); }
/// <summary> /// Main entry point /// </summary> public static void Main() { SoftwareSpi spi = new SoftwareSpi( clk: 25, sdi: 23, sdo: 24, cs: 5, settings: new SpiConnectionSettings(-1) { DataBitLength = Tlc1543.SpiDataBitLength }); Tlc1543 adc = new Tlc1543(spi); Channel[] channels = new Channel[] { Channel.A0, Channel.A1, Channel.A2, Channel.A3, Channel.A4 }; foreach (Channel channel in channels) { Console.WriteLine($"Channel {channel}: {adc.ReadChannel(channel)}"); } // or a bit faster // we ignore the first reading adc.ReadPreviousAndChargeChannel(channels[0]); for (int i = 0; i < channels.Length; i++) { // For last reading we need to pass something so let's pass test channel Channel nextChannel = i < channels.Length - 1 ? channels[i + 1] : Channel.SelfTestHalf; int previous = adc.ReadPreviousAndChargeChannel(nextChannel); Console.WriteLine($"Channel {channels[i]}: {previous}"); } // now continuously read from one channel Channel ch = Channel.A0; int numberOfReadings = 10; adc.ReadPreviousAndChargeChannel(ch); for (int i = 0; i < numberOfReadings; i++) { Console.WriteLine($"Channel {ch}: {adc.ReadPreviousAndChargeChannel(ch)}"); } }
static void Main(string[] args) { var hardwareSpiSettings = new SpiConnectionSettings(0, 0) { ClockFrequency = 1000000 }; using (SpiDevice spi = new SoftwareSpi(clk: 6, miso: 23, mosi: 5, cs: 24)) // For hardware implementation replace it with following // using (SpiDevice spi = SpiDevice.Create(hardwareSpiSettings)) using (Mcp3008 mcp = new Mcp3008(spi)) { while (true) { double value = mcp.Read(0); value = value / 10.24; value = Math.Round(value); Console.WriteLine($"{value}%"); Thread.Sleep(500); } } }