static void Main(string[] args) { var options = ParseOptions(args); if (options == null) { return; } log.Info("-=Pca9685 Sample=-"); log.Info(m => m("Running {0}", Environment.OSVersion)); log.Info("Options:" + Environment.NewLine + options); var pulse = CalculatePulse(options.PwmFrequency, 50); log.Info(m => m("Pulse={0}", pulse)); if (Environment.OSVersion.Platform != PlatformID.Unix) { log.Warn("Windows detected. Exiting"); return; } log.Info("Connecting..."); try { using (var driver = new I2cDriver(options.SdaPin.ToProcessor(), options.SclPin.ToProcessor())) { log.Info("Creating device..."); var device = Pca9685Connection.Create(driver.Connect(options.DeviceAddress)); log.Info("Setting frequency..."); device.SetPwmUpdateRate(options.PwmFrequency); while (!Console.KeyAvailable) { log.Info(m => m("Set channel={0} to {1}", options.Channel, options.PwmOn)); device.SetPwm(options.Channel, 0, options.PwmOn); Thread.Sleep(1000); log.Info(m => m("Set channel={0} to {1}", options.Channel, options.PwmOff)); device.SetPwm(options.Channel, 0, options.PwmOff); Thread.Sleep(1000); } log.Info("Key pressed. Exiting."); } } catch (InvalidOperationException e) { log.Error("Failed to connect? Do you have a Pca9685 IC attached to the i2c line and powered on?", e); } }
private IPwmDevice GetRealDevice() { PwmFrequency = 60; DeviceAddress = 0x40; _i2cDriver = new I2cDriver(SdaPin.ToProcessor(), SclPin.ToProcessor()); Log.Info("Creating device..."); var device = Pca9685Connection.Create(_i2cDriver.Connect(DeviceAddress)); Log.Info("Setting frequency..."); device.SetPwmUpdateRate(PwmFrequency); // # Set frequency to 60 Hz IsConnected = true; return(device); }