private async Task doCommand2() { Tuple <string, int> command = await GetCommand(); string cmd = command.Item1; int val = command.Item2; #endif switch (cmd) { case "ledOn": IoTGPIO.LEDOn(); break; case "ledOff": IoTGPIO.LEDOff(); break; case "ledFlash": if (val > 0) { await IoTGPIO.LEDFlash(val); } break; case "buzzdOn": break; case "buzzOff": break; default: Debug.WriteLine("Invalid comamnd: " + cmd); break; } }
public async Task Loop() { for (int i = 0; i < numLoops; i++) { await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { LED.Fill = redBrush; }); #if (!LESSON2) && (!LESSON5) && (!LESSON6) && (!LESSON7) && (!LESSON1_0) IoTGPIO.LEDOn(); #endif #if LESSON1_0 //Periodic flash simulated LED #elif LESSON1_1 //Periodic Flash LED only #elif LESSON2 //LED on when input is hi. int val = IoTGPIO.ReadInput(); if (val == 1) { IoTGPIO.LEDOn(); } else { IoTGPIO.LEDOff(); } #elif LESSON3 //Send a string message to IoT Hub await Send(i); #elif LESSON4 //Recv a message from IoT Hub await recv(); #elif LESSON5 //Send a message to IoT Hub when input is hi. int val = IoTGPIO.ReadInput(); if (val == 1) { await Send(i); } #elif LESSON6 //Get a command as a received message and action it. await doCommand(); #elif LESSON7 //Get a command as a commande and action it. await doCommand2(); #elif LESSON8 //Read temperature and humidity data from SHT15 sensor await ReadTemp(); #elif LESSON9 //Send temperature and humidity data to IoT Hub await SendTemp(); #endif //Pause 400 mS for all await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(400)); /////////////// await this.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { LED.Fill = grayBrush; }); #if (!LESSON2) && (!LESSON5) && (!LESSON6) && (!LESSON7) && (!LESSON1_0) IoTGPIO.LEDOff(); #endif //Pause 600 mS for all await System.Threading.Tasks.Task.Delay(TimeSpan.FromMilliseconds(600)); } Application.Current.Exit(); }