Ejemplo n.º 1
0
        // This method will be called by the application framework when the page is first loaded.
        protected override async void OnNavigatedTo(NavigationEventArgs navArgs)
        {
            Debug.WriteLine("MainPage::OnNavigatedTo");

            await LessonWebAPI.MakeLessonWebApiCall();

            try
            {
                // Create a new InternetLed object
                mcp3008 = new MCP3008(ADCReferenceVoltage);

                // Initialize it for use
                mcp3008.Initialize();

                byte whichChannel = 0;

                for (int i = 0; i < 10; i++)
                {
                    // Read the first adc channel, this will get back an ADC value between MCP3008.MIN (0) and MCP3008.MAX (1023)
                    int adcValue = await mcp3008.ReadADC(whichChannel);

                    // The convert that to a voltage
                    float voltage = mcp3008.ADCToVoltage(adcValue);

                    Debug.WriteLine(String.Format("Channel: {0}, ADC Value: {1}, Voltage: {2}", whichChannel, adcValue, voltage));

                    // Wait 1 second between loops.
                    await Task.Delay(1000);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
Ejemplo n.º 2
0
        // This method will be called by the application framework when the page is first loaded.
        protected override async void OnNavigatedTo(NavigationEventArgs navArgs)
        {
            Debug.WriteLine("MainPage::OnNavigatedTo");

            await LessonWebAPI.MakeLessonWebApiCall();

            try
            {
                // Create a new InternetLed object
                mcp3008 = new MCP3008(ADCReferenceVoltage);

                // Initialize it for use
                mcp3008.Initialize();

                byte whichChannel = 0;

                for (int i = 0; i < 10; i++)
                {
                    // Read the first adc channel, this will get back an ADC value between MCP3008.MIN (0) and MCP3008.MAX (1023)
                    int adcValue = await mcp3008.ReadADC(whichChannel);

                    // The convert that to a voltage
                    float voltage = mcp3008.ADCToVoltage(adcValue);

                    Debug.WriteLine(String.Format("Channel: {0}, ADC Value: {1}, Voltage: {2}", whichChannel, adcValue, voltage));

                    // Wait 1 second between loops.
                    await Task.Delay(1000);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }