GHIElectronics.UAP.Shields.FEZHAT.CreateAsync C# (CSharp) Method

CreateAsync() public static method

Creates a new instance of the FEZ HAT.
public static CreateAsync ( ) : Task
return Task
        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.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;
        }