static void Main() { const ConnectorPin dacClock = ConnectorPin.P1Pin11; const ConnectorPin dacCs = ConnectorPin.P1Pin13; const ConnectorPin dacMosi = ConnectorPin.P1Pin15; Console.WriteLine("MCP-4822 Sample: Write a changing value on Channel A"); Console.WriteLine(); Console.WriteLine("\tClock: {0}", dacClock); Console.WriteLine("\tCS: {0}", dacCs); Console.WriteLine("\tMOSI: {0}", dacMosi); Console.WriteLine(); var driver = GpioConnectionSettings.DefaultDriver; using (var clockPin = driver.Out(dacClock)) using (var csPin = driver.Out(dacCs)) using (var mosiPin = driver.Out(dacMosi)) using (var dacConnection = new Mcp4822SpiConnection(clockPin, csPin, mosiPin)) using (var channel = new Mcp4822OutputAnalogPin(dacConnection, Mcp4822Channel.ChannelA)) { const decimal minimum = 0.0001m; var ticks = minimum; var up = true; while (!Console.KeyAvailable) { channel.Write(new AnalogValue(ticks)); if (up) { ticks *= 2; if (ticks >= 1) { up = false; } } else { ticks /= 2; if (ticks <= minimum) { up = true; } } Thread.Sleep(100); } } }
static void Main() { const ConnectorPin dacClock = ConnectorPin.P1Pin11; const ConnectorPin dacCs = ConnectorPin.P1Pin13; const ConnectorPin dacMosi = ConnectorPin.P1Pin15; Console.WriteLine("MCP-4822 Sample: Write a changing value on Channel A"); Console.WriteLine(); Console.WriteLine("\tClock: {0}", dacClock); Console.WriteLine("\tCS: {0}", dacCs); Console.WriteLine("\tMOSI: {0}", dacMosi); Console.WriteLine(); using (var dacConnection = new Mcp4822SpiConnection(dacClock.ToProcessor(), dacCs.ToProcessor(), dacMosi.ToProcessor(), 1)) { const decimal minimum = 0.0001m; var ticks = minimum; var up = true; while (!Console.KeyAvailable) { dacConnection.Write(Mcp4822Channel.ChannelA, ticks); if (up) { ticks *= 2; if (ticks >= 1) { up = false; } } else { ticks /= 2; if (ticks <= minimum) { up = true; } } Thread.Sleep(100); } } }
static void Main(string[] args) { var dacClock = ConnectorPin.P1Pin11.ToProcessor(); var dacCs = ConnectorPin.P1Pin13.ToProcessor(); var dacMosi = ConnectorPin.P1Pin15.ToProcessor(); using (var dacConnection = new Mcp4822SpiConnection(dacClock, dacCs, dacMosi, 1)) { Console.WriteLine("MC4822 Sample: Write a changing value on Channel A"); const decimal minimum = 0.0001m; var ticks = minimum; var up = true; while (!Console.KeyAvailable) { dacConnection.Write(Mcp4822Channel.ChannelA, ticks); if (up) { ticks *= 2; if (ticks >= 1) { up = false; } } else { ticks /= 2; if (ticks <= minimum) { up = true; } } Thread.Sleep(100); } } }
/// <summary> /// Initializes a new instance of the <see cref="Mcp4822OutputAnalogPin" /> class. /// </summary> /// <param name="connection">The connection.</param> /// <param name="channel">The channel.</param> public Mcp4822OutputAnalogPin(Mcp4822SpiConnection connection, Mcp4822Channel channel) { this.connection = connection; this.channel = channel; }
/// <summary> /// Creates an output analog pin. /// </summary> /// <param name="connection">The connection.</param> /// <param name="channel">The channel.</param> /// <param name="scale">The maximum.</param> /// <returns>The pin.</returns> public static Mcp4822OutputAnalogPin Out(this Mcp4822SpiConnection connection, Mcp4822Channel channel) { return(new Mcp4822OutputAnalogPin(connection, channel)); }