diff --git a/examples/MultiSwitch/MultiSwitch.ino b/examples/MultiSwitch/MultiSwitch.ino index 853e62c..ee3bcf1 100644 --- a/examples/MultiSwitch/MultiSwitch.ino +++ b/examples/MultiSwitch/MultiSwitch.ino @@ -8,18 +8,31 @@ boolean connectWifi(); //on/off callbacks -void lightOn(); -void lightOff(); -void secondOn(); -void secondOff(); +void switch1On(); +void switch1Off(); +void switch2On(); +void switch2Off(); -//------- Replace the following! ------ -char ssid[] = "xxx"; // your network SSID (name) -char password[] = "yyyy"; // your network key +//##################################################################### +//########## config your switch here ################################## +//##################################################################### + +const char ssid[] = "xxx"; // your network SSID (name) +const char password[] = "yyyy"; // your network key + +const char switch1Name[] = "xyz1"; // Alexa Name of the first Switch +const int switch1Pin = 1; // Switch 1 Pin + +const char switch2Name[] = "xyz2"; // Alexa Name of the second Switch +const int switch2Pin = 2; //Switch 2 Pin + +//##################################################################### +//########## end of config area ####################################### +//##################################################################### WemoManager wemoManager; -WemoSwitch *light = NULL; -WemoSwitch *second = NULL; +WemoSwitch *switch1 = NULL; +WemoSwitch *switch2 = NULL; const int ledPin = BUILTIN_LED; @@ -31,16 +44,30 @@ void setup() // connected WiFi.mode(WIFI_STA); WiFi.disconnect(); + pinMode(ledPin, OUTPUT); // initialize digital ledPin as an output. + pinMode(switch1Pin, OUTPUT); // initialize digital switch1Pin as an output. + pinMode(switch2Pin, OUTPUT); // initialize digital switch2Pin as an output. + delay(100); - + + digitalWrite(ledPin, HIGH); // Wemos BUILTIN_LED is active Low, so high is off + digitalWrite(switch1Pin, HIGH); // Wemos switch1Pin is active Low, so high is off + digitalWrite(switch2Pin, HIGH); // Wemos switch2Pin is active Low, so high is off + // Attempt to connect to Wifi network: Serial.print("Connecting Wifi: "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { Serial.print("."); - delay(500); - } + delay(200); + if(digitalRead(BUILTIN_LED)==LOW){ + digitalWrite(BUILTIN_LED, HIGH); + }else{ + digitalWrite(BUILTIN_LED, LOW); + } + } + digitalWrite(ledPin, LOW); Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); @@ -49,14 +76,10 @@ void setup() wemoManager.begin(); // Format: Alexa invocation name, local port no, on callback, off callback - light = new WemoSwitch("test lights", 80, lightOn, lightOff); - second = new WemoSwitch("second lights", 81, secondOn, secondOff); - wemoManager.addDevice(*light); - wemoManager.addDevice(*second); - - pinMode(ledPin, OUTPUT); // initialize digital ledPin as an output. - delay(10); - digitalWrite(ledPin, HIGH); // Wemos BUILTIN_LED is active Low, so high is off + switch1 = new WemoSwitch(switch1Name, 80, switch1On, switch1Off); + switch2 = new WemoSwitch(switch2Name, 81, switch2On, switch2Off); + wemoManager.addDevice(*switch1); + wemoManager.addDevice(*switch2); } void loop() @@ -64,22 +87,22 @@ void loop() wemoManager.serverLoop(); } -void lightOn() { +void switch1On() { Serial.print("Switch 1 turn on ..."); - digitalWrite(ledPin, LOW); + digitalWrite(switch1Pin, LOW); } -void lightOff() { +void switch1Off() { Serial.print("Switch 1 turn off ..."); - digitalWrite(ledPin, HIGH); + digitalWrite(switch1Pin, HIGH); } -void secondOn() { +void switch2On() { Serial.print("Switch 2 turn on ..."); - digitalWrite(ledPin, LOW); + digitalWrite(switch2Pin, LOW); } -void secondOff() { +void switch2Off() { Serial.print("Switch 2 turn off ..."); - digitalWrite(ledPin, HIGH); + digitalWrite(switch2Pin, HIGH); }