ulvis.paste.net

Paste Search Dynamic
Recent pastes
flash firmware
  1. #include <LWiFi.h>
  2. #include "MCS.h"
  3.  
  4. char _lwifi_ssid[] = "你的AP ID";
  5. char _lwifi_pass[] = "你的AP PW";
  6. String upload_led;
  7. int buttonPinRoom = 2;
  8. int buttonPinWC = 3;
  9. int buttonPinLiving = 4;
  10. int buttonPinBalcony = 5;
  11. boolean i;
  12.  
  13. MCSDisplayOnOff buttonRoom("buttonRoom");
  14. MCSDisplayOnOff buttonWC("buttonWC");
  15. MCSDisplayOnOff buttonLiving("buttonLiving");
  16. MCSDisplayOnOff buttonBalcony("buttonBalcony");
  17. MCSDevice mcs("MCS的DeviceID", "MCS的Device key");
  18.  
  19. void setup()
  20. {
  21.   Serial.begin(9600);
  22.  
  23.   mcs.addChannel(buttonRoom);
  24.   mcs.addChannel(buttonWC);
  25.   mcs.addChannel(buttonLiving);
  26.   mcs.addChannel(buttonBalcony);
  27.   Serial.println("Wi-Fi 開始連線");
  28.   while (WiFi.begin(_lwifi_ssid, _lwifi_pass) != WL_CONNECTED) { delay(1000); }
  29.   Serial.println("Wi-Fi 連線成功");
  30.   while(!mcs.connected()) { mcs.connect(); }
  31.   Serial.println("MCS 連線成功");
  32.   Serial.begin(9600);
  33.   pinMode(LED_BUILTIN, OUTPUT);
  34.   pinMode(buttonPinRoom, INPUT);
  35.   pinMode(buttonPinWC, INPUT);
  36.   pinMode(buttonPinLiving, INPUT);
  37.   pinMode(buttonPinBalcony, INPUT);
  38. }
  39.  
  40. void loop()
  41. {
  42.   while (!mcs.connected()) {
  43.     mcs.connect();
  44.     if (mcs.connected()) { Serial.println("MCS 已重新連線"); }
  45.   }
  46.   mcs.process(100);
  47.  
  48.   if(digitalRead(buttonPinRoom)==1) {  //開關啟動
  49.     i = 1;
  50.     buttonRoom.set(i);
  51.     Serial.println("1");
  52.     digitalWrite(LED_BUILTIN, HIGH);
  53.   } else {  //開關未啟動
  54.     i = 0;
  55.     buttonRoom.set(i);
  56.     Serial.println("0");
  57.     digitalWrite(LED_BUILTIN, LOW);
  58.     }
  59.  
  60.    if(digitalRead(buttonPinWC)==1) {  //開關啟動
  61.     i = 1;
  62.     buttonWC.set(i);
  63.     Serial.println("1");
  64.     digitalWrite(LED_BUILTIN, HIGH);
  65.   } else {  //開關未啟動
  66.     i = 0;
  67.     buttonWC.set(i);
  68.     Serial.println("0");
  69.     digitalWrite(LED_BUILTIN, LOW);
  70.     }
  71.        
  72.   if(digitalRead(buttonPinLiving)==1) {  //開關啟動
  73.     i = 1;
  74.     buttonLiving.set(i);
  75.     Serial.println("1");
  76.     digitalWrite(LED_BUILTIN, HIGH);
  77.   } else {  //開關未啟動
  78.     i = 0;
  79.     buttonLiving.set(i);
  80.     Serial.println("0");
  81.     digitalWrite(LED_BUILTIN, LOW);
  82.     }
  83.  
  84. if(digitalRead(buttonPinBalcony)==1) {  //開關啟動
  85.     i = 1;
  86.     buttonBalcony.set(i);
  87.     Serial.println("1");
  88.     digitalWrite(LED_BUILTIN, HIGH);
  89.   } else {  //開關未啟動
  90.     i = 0;
  91.     buttonBalcony.set(i);
  92.     Serial.println("0");
  93.     digitalWrite(LED_BUILTIN, LOW);
  94.     }
  95.  
  96.   delay(100);
  97. }
Parsed in 0.022 seconds