/// <summary> /// Constructor for a single PWM click. /// </summary> /// <param name="socknum">mikroBUS socket number.</param> /// <param name="freq">PWM pulse frequency in Hz.</param> /// <param name="addr">I<sup>2</sup>C slave address.</param> /// <param name="remdev">Remote I/O device object.</param> public Board(int socknum, int freq, int addr = DefaultAddress, IO.Remote.Device remdev = null) { // Create Remote I/O server device object, if one wasn't supplied if (remdev == null) { remdev = new IO.Remote.Device(); } // Create a mikroBUS socket object IO.Remote.mikroBUS.Socket S = new IO.Remote.mikroBUS.Socket(socknum); IO.Interfaces.I2C.Bus bus; if (IO.Remote.mikroBUS.Shield.I2CBus is null) { bus = remdev.I2C_Create(S.I2CBus); } else { bus = IO.Remote.mikroBUS.Shield.I2CBus; } mydev = new IO.Devices.PCA9685.Device(bus, addr, freq); }
static void Main(string[] args) { Console.WriteLine("\nPCA9685 GPIO Output Test\n"); if (args.Length != 2) { Console.WriteLine("Usage: test_pca9685_gpio <bus> <addr>\n"); Environment.Exit(1); } // Create GPIO pin object IO.Interfaces.I2C.Bus bus = new IO.Objects.libsimpleio.I2C.Bus(args[0]); IO.Devices.PCA9685.Device dev = new IO.Devices.PCA9685.Device(bus, int.Parse(args[1]), 5000); IO.Interfaces.GPIO.Pin GPIO0 = new IO.Devices.PCA9685.GPIO.Pin(dev, 0, false); // Toggle the GPIO output Console.WriteLine("Press CONTROL-C to exit"); for (;;) { GPIO0.state = !GPIO0.state; } }
/// <summary> /// Constructor for a single PWM click. /// </summary> /// <param name="socknum">mikroBUS socket number.</param> /// <param name="freq">PWM pulse frequency in Hz.</param> /// <param name="addr">I<sup>2</sup>C slave address.</param> public Board(int socknum, int freq, int addr = DefaultAddress) { IO.Objects.libsimpleio.mikroBUS.Socket S = new IO.Objects.libsimpleio.mikroBUS.Socket(socknum); IO.Interfaces.I2C.Bus bus; if (IO.Objects.libsimpleio.mikroBUS.Shield.I2CBus is null) { bus = new IO.Objects.libsimpleio.I2C.Bus(S.I2CBus); } else { bus = IO.Objects.libsimpleio.mikroBUS.Shield.I2CBus; } mydev = new IO.Devices.PCA9685.Device(bus, addr, freq); }
static void Main(string[] args) { Console.WriteLine("\nPCA9685 PWM Output Test\n"); if (args.Length != 2) { Console.WriteLine("Usage: test_grove_i2c_adc <bus> <addr>\n"); Environment.Exit(1); } // Create PWM output object IO.Interfaces.I2C.Bus bus = new IO.Objects.libsimpleio.I2C.Bus(args[0]); IO.Devices.PCA9685.Device dev = new IO.Devices.PCA9685.Device(bus, int.Parse(args[1]), 1000); IO.Interfaces.PWM.Output PWM0 = new IO.Devices.PCA9685.PWM.Output(dev, 0); // Sweep PWM pulse width back and forth Console.WriteLine("Press CONTROL-C to exit"); for (;;) { int n; for (n = 0; n < 100; n++) { PWM0.dutycycle = n; System.Threading.Thread.Sleep(50); } for (n = 100; n >= 0; n--) { PWM0.dutycycle = n; System.Threading.Thread.Sleep(50); } } }
static void Main(string[] args) { Console.WriteLine("\nPCA9685 Servo Output Test\n"); if (args.Length != 2) { Console.WriteLine("Usage: test_pca9685_pwm <bus> <addr>\n"); Environment.Exit(1); } // Create servo output object IO.Interfaces.I2C.Bus bus = new IO.Objects.libsimpleio.I2C.Bus(args[0]); IO.Devices.PCA9685.Device dev = new IO.Devices.PCA9685.Device(bus, int.Parse(args[1]), 50); IO.Interfaces.Servo.Output Servo0 = new IO.Devices.PCA9685.Servo.Output(dev, 0); // Sweep servo position back and forth Console.WriteLine("Press CONTROL-C to exit"); for (;;) { int n; for (n = -100; n < 100; n++) { Servo0.position = n / 100.0; System.Threading.Thread.Sleep(50); } for (n = 100; n >= -100; n--) { Servo0.position = n / 100.0; System.Threading.Thread.Sleep(50); } } }