以下是用wifi遠端遙控和紅外線感測器的程式碼
紅色部份是驗證有錯
拜託大神幫忙解答
#include <WiShield.h> #define WIRELESS_MODE_INFRA 1 #define WIRELESS_MODE_ADHOC 2 unsigned char local_ip[] = {192,168,0,101}; //arduino的wi-fi板的local_ip unsigned char gateway_ip[] = {192,168,0,1}; //arduino的wi-fi板的 gateway_ip unsigned char subnet_mask[] = {255,255,255,0}; //arduino的wi-fi板的subnet_mask char ssid[] = {"dlink"}; //arduino的wi-fi板連的無線網域名稱 unsigned char security_type = 0; const prog_char security_passphrase[] PROGMEM = {"abcde"}; prog_uchar wep_keys[] PROGMEM = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; unsigned char wireless_mode = WIRELESS_MODE_INFRA; unsigned char ssid_len; unsigned char security_passphrase_len; char recvChar; char sms[8]; char message[32]; const int PIRSensor = 2; const int ledPin = 13;
const int Motor_M1 = 7; //設 Motor_M1為Arduino板上的孔7 int sensorValue = 0;
struct NetworkPackage { int dataLength; char data[32]; }; NetworkPackage mNetworkPack; void setup() {
Serial.begin(9600);
recvChar = NULL; WiFi.init();
pinMode(Motor_M1, OUTPUT); pinMode(PIRSensor, INPUT); pinMode(ledPin, OUTPUT); } void loop() { if(NULL != recvChar) {
if(!strcmp(mNetworkPack.data, "bulbon")) //當app傳的data是bulbon Arduino執行bulbon函數 bulbon(0,0); if(!strcmp(mNetworkPack.data, "bulboff")) //當app傳的data是bulboff Arduino執行bulboff函數 bulboff(0,0); if(!strcmp(mNetworkPack.data, "fanon")) //當app傳的data是fanon Arduino執行fanon函數 fanon(0,0); if(!strcmp(mNetworkPack.data, "fanoff")) //當app傳的data是fanoff Arduino執行fanoff函數 fanoff(0,0);
recvChar = NULL; }
WiFi.run();
sensorValue = digitalRead(PIRSensor);
if (sensorValue == HIGH) { //紅外線程式 digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } }
void bulbon(byte flag, byte numOfValues) //電燈開函數 { Serial.println("bulbon : ");
digitalWrite( Motor_M1, HIGH); // 孔7 電位提高
}
void bulboff(byte flag, byte numOfValues) //電燈關函數 { Serial.println("bulboff : "); digitalWrite( Motor_M1, LOW); // 孔7 電位降低
} void fanon(byte flag, byte numOfValues) //電扇開函數 { Serial.println("fanon : "); digitalWrite( Motor_M1, HIGH); // 孔7 電位提高
} void fanoff(byte flag, byte numOfValues) //電扇關函數 { Serial.println("fanoff : "); digitalWrite( Motor_M1, LOW); // 孔7 電位降低
}
|