// This will perform a web API call and then depending on the returned millisecond value // return an eLedState value // millisecond value > 5 = eLedState.On // anything else = eLedState.off public async Task <eLedState> MakeWebApiCall() { Debug.WriteLine("InternetLed::MakeWebApiCall"); eLedState computedLedState = eLedState.On; // Prepare the web API call WebRequest request = WebRequest.Create(WebAPIURL); // Wait for the response notification WebResponse response = await request.GetResponseAsync(); // Read the response string into memory. StreamReader streamReader = new StreamReader(response.GetResponseStream()); string responseString = streamReader.ReadToEnd(); if (responseString[19] > '5') { // If the millisecond part of the string is greater than 5 turn on the led computedLedState = eLedState.On; } else { // Otherwise turn it off computedLedState = eLedState.Off; } // return the computed led state return(computedLedState); }
// Change the state of the led from on to off or off to on public void Blink() { if (LedState == eLedState.On) { LedState = eLedState.Off; } else { LedState = eLedState.On; } }
public void InitalizeLed() { Debug.WriteLine("InternetLed::InitalizeLed"); // Now setup the LedControlPin gpio = GpioController.GetDefault(); LedControlGPIOPin = gpio.OpenPin(LedControlPin); LedControlGPIOPin.SetDriveMode(GpioPinDriveMode.Output); // Get the current pin value GpioPinValue startingValue = LedControlGPIOPin.Read(); _LedState = (startingValue == GpioPinValue.Low) ? eLedState.On : eLedState.Off; }