GetControllersAsync() public method

Gets the AdcController instances for each controller provider.
public GetControllersAsync ( ) : IAsyncOperation>
return IAsyncOperation>
Exemplo n.º 1
0
 private async Task InitLightAdc()
 {
     adcManager = new AdcProviderManager();
     adcManager.Providers.Add(new ADS1015(ADS1015.Gain.Volt5));
     var ads1015 = (await adcManager.GetControllersAsync())[0];
     light = new Ldr(ads1015.OpenChannel(2));
 }
        public async Task InitaliseAdc()
        {
            if (Adc == null) { return; }

            adcManager = new AdcProviderManager();
            adcManager.Providers.Add(new MCP3002());
            adcControllers = await adcManager.GetControllersAsync();
        }
        public async Task InitaliseAdcAsync() {
            adcManager = new AdcProviderManager();
            adcManager.Providers.Add(new ADS1015(gain));
            adcControllers = await adcManager.GetControllersAsync();

            Adc = adcControllers[0];

            IsAdcInitalised = true;
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();


            // How to use the ADS1015 and MCP3002 ADC/Converters

            AdcProviderManager adcManager = new AdcProviderManager();

            adcManager.Providers.Add(new ADS1015(ADS1015.Gain.Volt33));     // Load up ADS1015 4 Channel ADC Converter
            adcManager.Providers.Add(new MCP3002());                       // Load up MCP3002 2 Channel ADC Converter

            IReadOnlyList<AdcController> adcControllers = await adcManager.GetControllersAsync();  // load ADCs


            //use the ADCs create above
            Ldr light = new Ldr(adcControllers[0].OpenChannel(0)); // create new light sensor using the ADS1015 ADC provider
            MCP9700A temp = new MCP9700A(adcControllers[1].OpenChannel(0)); // create temperature sensor using MCP3002 ADC Provider

            var lightLevel = light.ReadValue;        // read light level from the first ADC ADS1015
            var lightRatio = light.ReadRatio;

            var celsius = temp.Temperature.DegreesCelsius;  // read temp in celsius
            var fahrenheit = temp.Temperature.DegreesFahrenheit;  // read temp in celsius


            BMP280 tempAndPressure = new BMP280();

            var degreesCelsius = tempAndPressure.Temperature.DegreesCelsius;  // read temp in celsius - plenty of other units
            var degreesFahrenheit = tempAndPressure.Temperature.DegreesFahrenheit;

            var bars = tempAndPressure.Pressure.Bars;       // read air pressure in bars - plenty of other units
            var hectopascals = tempAndPressure.Pressure.Hectopascals;  // read air pressure in Hectopascals
            var Atmospheres = tempAndPressure.Pressure.Atmospheres;


            // LED demo

            Led led = new Led(4);  // open led on pin 4
            led.On();  // turn on
            await Task.Delay(1000);  // wait for 1 second
            led.Off(); // turn off

            // relay Demo
            Relay relay = new Relay(6);
            relay.On(); // turn relay on
            await Task.Delay(1000);  // wait for 1 second
            led.Off(); // turn relay off


            // motor demo
            Motor leftMotor = new Motor(22, 24);
            Motor rightMotor = new Motor(12, 25);

            //now do a tight circle
            leftMotor.Forward();
            rightMotor.Backward();
            await Task.Delay(5000);  // wait for 5 second
            leftMotor.Stop();
            rightMotor.Stop();
        }