烧录地址填错了,看文档,附链接http://docs.gizwits.com/zh-cn/de ... AF%B4%E6%98%8E.html |
为什么加Q群管理员还不同意呢 |
以下是自动生成的代码,已经按照教程把两个程序的代码合并,已成功上传到UNO #include <Gizwits.h> #include <Wire.h> #include <SoftwareSerial.h> SoftwareSerial mySerial(A2, A3); // A2 -> RX, A3 -> TX Gizwits myGizwits; #define KEY1 6 #define KEY2 7 #define KEY1_SHORT_PRESS 1 #define KEY1_LONG_PRESS 2 #define KEY2_SHORT_PRESS 4 #define KEY2_LONG_PRESS 8 #define NO_KEY 0 #define KEY_LONG_TIMER 3 unsigned long Last_KeyTime = 0; unsigned long gokit_time_s(void) { return millis() / 1000; } char gokit_key1down(void) { unsigned long keep_time = 0; if (digitalRead(KEY1) == LOW) { delay(100); if (digitalRead(KEY1) == LOW) { keep_time = gokit_time_s(); while (digitalRead(KEY1) == LOW) { if ((gokit_time_s() - keep_time) > KEY_LONG_TIMER) { Last_KeyTime = gokit_time_s(); return KEY1_LONG_PRESS; } } //until open the key if ((gokit_time_s() - Last_KeyTime) > KEY_LONG_TIMER) { return KEY1_SHORT_PRESS; } return 0; } return 0; } return 0; } char gokit_key2down(void) { int unsigned long keep_time = 0; if (digitalRead(KEY2) == LOW) { delay(100); if (digitalRead(KEY2) == LOW) { keep_time = gokit_time_s(); while (digitalRead(KEY2) == LOW) //until open the key { if ((gokit_time_s() - keep_time) > KEY_LONG_TIMER) { Last_KeyTime = gokit_time_s(); return KEY2_LONG_PRESS; } } if ((gokit_time_s() - Last_KeyTime) > KEY_LONG_TIMER) { return KEY2_SHORT_PRESS; } return 0; } return 0; } return 0; } char gokit_keydown(void) { char ret = 0; ret |= gokit_key2down(); ret |= gokit_key1down(); return ret; } /** * KEY_Handle * @param none * @return none */ void KEY_Handle(void) { /* Press for over than 3 second is Long Press */ switch (gokit_keydown()) { case KEY1_SHORT_PRESS: mySerial.println(F("KEY1_SHORT_PRESS , Production Test Mode ")); myGizwits.setBindMode(WIFI_PRODUCTION_TEST); break; case KEY1_LONG_PRESS: mySerial.println(F("KEY1_LONG_PRESS ,Wifi Reset")); myGizwits.setBindMode(WIFI_RESET_MODE); break; case KEY2_SHORT_PRESS: mySerial.println(F("KEY2_SHORT_PRESS Soft AP mode")); myGizwits.setBindMode(WIFI_SOFTAP_MODE); //Soft AP mode break; case KEY2_LONG_PRESS: mySerial.println(F("KEY2_LONG_PRESS ,AirLink mode")); myGizwits.setBindMode(WIFI_AIRLINK_MODE); //AirLink mode break; default: break; } } void setup() { pinMode(KEY1, INPUT_PULLUP); pinMode(KEY2, INPUT_PULLUP); mySerial.begin(115200); myGizwits.begin(); mySerial.println("GoKit init OK \n"); } void wifiStatusHandle() { if(myGizwits.wifiHasBeenSet(WIFI_SOFTAP)) { mySerial.println(F("WIFI_SOFTAP!")); } if(myGizwits.wifiHasBeenSet(WIFI_AIRLINK)) { mySerial.println(F("WIFI_AIRLINK!")); } if(myGizwits.wifiHasBeenSet(WIFI_STATION)) { mySerial.println(F("WIFI_STATION!")); } if(myGizwits.wifiHasBeenSet(WIFI_CON_ROUTER)) { mySerial.println(F("WIFI_CON_ROUTER!")); } if(myGizwits.wifiHasBeenSet(WIFI_DISCON_ROUTER)) { mySerial.println(F("WIFI_DISCON_ROUTER!")); } if(myGizwits.wifiHasBeenSet(WIFI_CON_M2M)) { mySerial.println(F("WIFI_CON_M2M!")); } if(myGizwits.wifiHasBeenSet(WIFI_DISCON_M2M)) { mySerial.println(F("WIFI_DISCON_M2M!")); } } void loop() { //Configure network //if(XXX) //Trigger Condition //myGizwits.setBindMode(0x02); //0x01:Enter AP Mode;0x02:Enter Airlink Mode /* float varW_temp = 0;//Add Sensor Data Collection myGizwits.write(VALUE_temp, varW_temp); //binary datapoint handle */ KEY_Handle();//key handle , network configure wifiStatusHandle();//WIFI Status Handle myGizwits.process(); } |
版权与免责声明 © 2006-2024 Gizwits IoT Technology Co., Ltd. ( 粤ICP备11090211号 )