public IndirectedPwmOutput(int channel, PCA9685 pwm) { this.channel = channel; this.pwm = pwm; }
/// <summary> /// Creates a new instance of the FEZ HAT. /// </summary> /// <returns>The new instance.</returns> public static async Task <FEZHAT> CreateAsync() { var gpioController = GpioController.GetDefault(); var i2cController = (await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector(FEZHAT.I2cDeviceName)))[0]; var hat = new FEZHAT(); hat.accelerometer = new MMA8453(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(MMA8453.GetAddress(false)))); hat.analog = new ADS7830(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(ADS7830.GetAddress(false, false)))); hat.pwm = new PCA9685(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9685.GetAddress(true, true, true, true, true, true))), gpioController.OpenPin(13)); hat.pwm.OutputEnabled = true; hat.pwm.Frequency = 1500; hat.dio16 = gpioController.OpenPin(16); hat.dio26 = gpioController.OpenPin(26); hat.dio24 = gpioController.OpenPin(24); hat.dio18 = gpioController.OpenPin(18); hat.dio22 = gpioController.OpenPin(22); hat.dio16.SetDriveMode(GpioPinDriveMode.Input); hat.dio26.SetDriveMode(GpioPinDriveMode.Input); hat.dio24.SetDriveMode(GpioPinDriveMode.Output); hat.dio18.SetDriveMode(GpioPinDriveMode.Input); hat.dio22.SetDriveMode(GpioPinDriveMode.Input); hat.motorEnable = gpioController.OpenPin(12); hat.motorEnable.SetDriveMode(GpioPinDriveMode.Output); hat.motorEnable.Write(GpioPinValue.High); hat.MotorA = new Motor(hat.pwm, 14, 27, 23); hat.MotorB = new Motor(hat.pwm, 13, 6, 5); hat.D2 = new RgbLed(hat.pwm, 1, 0, 2); hat.D3 = new RgbLed(hat.pwm, 4, 3, 15); hat.S1 = new Servo(hat.pwm, 9); hat.S2 = new Servo(hat.pwm, 10); return(hat); }
protected async override Task Initialize() { this.gpioMap = FEZCream.CreateGpioMap(); this.analogMap = FEZCream.CreateAnalogMap(); this.pwmMap = FEZCream.CreatePwmMap(); this.analogSharedMap = FEZCream.CreateAnalogSharedMap(); this.pwmSharedMap = FEZCream.CreatePwmSharedMap(); this.analog = new ADS7830(await GNI.I2cDevice.CreateInterfaceAsync("I2C1", new I2cConnectionSettings(ADS7830.GetAddress(false, false)))); this.pwm = new PCA9685(await GNI.I2cDevice.CreateInterfaceAsync("I2C1", new I2cConnectionSettings(PCA9685.GetAddress(true, true, true, true, true, true)))); this.gpios = new PCA9535[2]; this.gpios[0] = new PCA9535(await GNI.I2cDevice.CreateInterfaceAsync("I2C1", new I2cConnectionSettings(PCA9535.GetAddress(true, true, false))), await GNI.DigitalIO.CreateInterfaceAsync(22)); this.gpios[1] = new PCA9535(await GNI.I2cDevice.CreateInterfaceAsync("I2C1", new I2cConnectionSettings(PCA9535.GetAddress(true, false, true))), await GNI.DigitalIO.CreateInterfaceAsync(26)); for (var i = 2; i <= 7; i++) { this.gpios[0].SetDriveMode(i, GpioPinDriveMode.Output); this.gpios[0].Write(i, true); } Socket socket; socket = this.CreateSocket(1); socket.AddSupportedTypes(SocketType.I); socket.SetNativePin(SocketPinNumber.Three, 18); socket.NativeI2cDeviceId = "I2C1"; socket.DigitalIOCreator = this.DigitalIOCreator; socket = this.CreateSocket(2); socket.AddSupportedTypes(SocketType.U); socket.NativeSerialDeviceId = "COM1"; socket.DigitalIOCreator = this.DigitalIOCreator; socket = this.CreateSocket(3); socket.AddSupportedTypes(SocketType.S, SocketType.X); socket.SetNativePin(SocketPinNumber.Three, 24); socket.SetNativePin(SocketPinNumber.Four, 25); socket.SetNativePin(SocketPinNumber.Five, 13); socket.NativeSpiDeviceId = "SPI0"; socket.NativeSpiChipSelectPin = 0; socket = this.CreateSocket(4); socket.AddSupportedTypes(SocketType.Y); socket.SetNativePin(SocketPinNumber.Three, 6); socket.DigitalIOCreator = this.DigitalIOCreator; socket = this.CreateSocket(5); socket.AddSupportedTypes(SocketType.A); socket.SetNativePin(SocketPinNumber.Three, 12); socket.DigitalIOCreator = this.DigitalIOCreator; socket.AnalogIOCreator = this.AnalogIOCreator; socket = this.CreateSocket(6); socket.AddSupportedTypes(SocketType.A); socket.SetNativePin(SocketPinNumber.Three, 16); socket.DigitalIOCreator = this.DigitalIOCreator; socket.AnalogIOCreator = this.AnalogIOCreator; socket = this.CreateSocket(7); socket.AddSupportedTypes(SocketType.P, SocketType.Y); socket.SetNativePin(SocketPinNumber.Three, 5); socket.DigitalIOCreator = this.DigitalIOCreator; socket.PwmOutputCreator = this.PwmOutputCreator; socket = this.CreateSocket(8); socket.AddSupportedTypes(SocketType.P, SocketType.Y); socket.SetNativePin(SocketPinNumber.Three, 27); socket.DigitalIOCreator = this.DigitalIOCreator; socket.PwmOutputCreator = this.PwmOutputCreator; socket = this.CreateSocket(9); socket.AddSupportedTypes(SocketType.I); socket.SetNativePin(SocketPinNumber.Three, 23); socket.NativeI2cDeviceId = "I2C1"; socket.DigitalIOCreator = this.DigitalIOCreator; }
/// <summary> /// Releases all resources used by the libPWMdeviceControl.DeviceControl object. /// </summary> public void Dispose() { CancelPeriodicTimer(); _device?.Dispose(); _device = null; }
public static async Task <FEZUtilityShield> CreateAsync() { if (null == instance) { GpioController gpioController; instance = new FEZUtilityShield(); gpioController = await GpioController.GetDefaultAsync().AsTask().ConfigureAwait(false); DeviceInformation i2cController; i2cController = (await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector("I2C1")).AsTask().ConfigureAwait(false))[0]; instance.analog = new ADS7830(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(ADS7830.GetAddress(false, false)))); instance.pwm = new PCA9685(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9685.GetAddress(true, true, true, true, true, true)))); instance.gpio = new PCA9535(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9535.GetAddress(true, true, false))), gpioController.OpenPin(22)); } return(instance); }
/// <summary> /// Creates a new instance of the FEZ Utility. /// </summary> /// <returns>The new instance.</returns> public static async Task <FEZUtility> CreateAsync() { var gpioController = GpioController.GetDefault(); var i2cController = (await DeviceInformation.FindAllAsync(I2cDevice.GetDeviceSelector("I2C1")))[0]; var hat = new FEZUtility(); hat.analog = new ADS7830(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(ADS7830.GetAddress(false, false)))); hat.pwm = new PCA9685(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9685.GetAddress(true, true, true, true, true, true)))); hat.gpio = new PCA9535(await I2cDevice.FromIdAsync(i2cController.Id, new I2cConnectionSettings(PCA9535.GetAddress(true, true, false))), gpioController.OpenPin(22)); hat.gpio.Write((int)Led.Led1, false); hat.gpio.Write((int)Led.Led2, false); hat.gpio.SetDriveMode((int)Led.Led1, GpioPinDriveMode.Output); hat.gpio.SetDriveMode((int)Led.Led2, GpioPinDriveMode.Output); return(hat); }
public PCA9685PWMChannel(PCA9685 pwm, int channel) { this.pwm = pwm; this.channel = channel; }
static void Main(string[] args) { var pca9685 = new PCA9685(); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"PCA9685 is ready on I2C bus {pca9685.BusId} with address {pca9685.Address}"); while (true) { Console.WriteLine(); try { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Command: F {freq_hz} | P {prescale} | S {off} | S {on} {off} | S {on} {off} {channel}"); Console.ResetColor(); var command = Console.ReadLine().ToLower().Split(' '); switch (command[0][0]) { case 'f': { var freq = double.Parse(command[1]); pca9685.SetPwmFrequency(freq); var prescale = pca9685.GetPrescale(freq); freq = pca9685.GetFreq(prescale); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"PWM Frequency has been set to about {freq}Hz with prescale is {prescale}"); break; } case 'p': { var prescale = (byte)int.Parse(command[1]); pca9685.SetPwmFrequency(prescale); var freq = pca9685.GetFreq(prescale); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"PWM Frequency has been set to about {freq}Hz with prescale is {prescale}"); break; } case 's': { switch (command.Length) { case 2: { var off = int.Parse(command[1]); pca9685.SetPwm(0, off); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"PWM pulse width has been set to {off}/4096"); break; } case 3: { var on = int.Parse(command[1]); var off = int.Parse(command[2]); pca9685.SetPwm(on, off); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"PWM pulse pull up at {on} and pull down at {off}"); break; } case 4: { var on = int.Parse(command[1]); var off = int.Parse(command[2]); var channel = int.Parse(command[3]); pca9685.SetPwm(on, off, channel); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"PWM pulse pull up at {on} and pull down at {off} on channel {channel}"); break; } } break; } } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.GetBaseException().Message); Console.ResetColor(); } } }