求救 兩組程式碼做結合~-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2821|回复: 2

求救 兩組程式碼做結合~

[复制链接]
发表于 2013-11-15 18:04 | 显示全部楼层 |阅读模式
本帖最后由 man3838 于 2013-11-15 18:09 编辑

兩組程式碼結合後
紅外線卻失效了 求解

遙控開關
#include <WiShield.h>
#define WIRELESS_MODE_INFRA   1
#define WIRELESS_MODE_ADHOC   2
unsigned char local_ip[]       = {192,168,0,101};  
unsigned char gateway_ip[]     = {192,168,0,1};   
unsigned char subnet_mask[]    = {255,255,255,0};
char ssid[] = {"dlink"};   
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 Motor_M1 = 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);

}
void loop()
{
   if(NULL != recvChar) {
      
      if(!strcmp(mNetworkPack.data, "bulbon"))
        bulbon(0,0);
      if(!strcmp(mNetworkPack.data, "bulboff"))
        bulboff(0,0);
        if(!strcmp(mNetworkPack.data, "fanon"))
        fanon(0,0);
      if(!strcmp(mNetworkPack.data, "fanoff"))
        fanoff(0,0);
         
      recvChar = NULL;
   }
   
   WiFi.run();  
   
}
void bulbon(byte flag, byte numOfValues)
{
  Serial.println("bulbon : ");
  digitalWrite( Motor_M1, HIGH);
  
}
void bulboff(byte flag, byte numOfValues)
{
  Serial.println("bulboff : ");
  digitalWrite( Motor_M1, LOW);
   
}
void fanon(byte flag, byte numOfValues)
{
  Serial.println("fanon : ");
  digitalWrite( Motor_M1, HIGH);
   
}
void fanoff(byte flag, byte numOfValues)
{
  Serial.println("fanoff : ");
  digitalWrite( Motor_M1, LOW);
}



紅外線感應器PIR

const int PIRSensor = 2; // 紅外線動作感測器連接的腳位

const int ledPin = 13; // LED 腳位

int sensorValue = 0; // 紅外線動作感測器訊號變數

int val = 0;

void setup() {

Serial.begin(4800); //設定終端機的Port位
pinMode(PIRSensor, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop(){


sensorValue = digitalRead(PIRSensor);

if (sensorValue == HIGH) {
digitalWrite(ledPin, HIGH); // 有人,開燈
val = digitalRead(13);
Serial.println("1234");

}

else {

digitalWrite(ledPin, LOW); // 沒人,關燈

}

}

結合後

#include <WiShield.h>
#define WIRELESS_MODE_INFRA   1
#define WIRELESS_MODE_ADHOC   2
unsigned char local_ip[]       = {192,168,0,101};  
unsigned char gateway_ip[]     = {192,168,0,1};   
unsigned char subnet_mask[]    = {255,255,255,0};
char ssid[] = {"dlink"};   
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;     
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"))
        bulbon(0,0);
      if(!strcmp(mNetworkPack.data, "bulboff"))
        bulboff(0,0);
        if(!strcmp(mNetworkPack.data, "fanon"))
        fanon(0,0);
      if(!strcmp(mNetworkPack.data, "fanoff"))
        fanoff(0,0);
     
      recvChar = NULL;
   }
   
   WiFi.run();
   
   sensorValue = digitalRead(PIRSensor);

if (sensorValue == HIGH) {
   digitalWrite(ledPin, LOW);
}
else {
digitalWrite(ledPin, HIGH);
}
}
void bulbon(byte flag, byte numOfValues)
{
  Serial.println("bulbon : ");
  digitalWrite( Motor_M1, HIGH);

}
void bulboff(byte flag, byte numOfValues)
{
  Serial.println("bulboff : ");
  digitalWrite( Motor_M1, LOW);
   
}
void fanon(byte flag, byte numOfValues)
{
  Serial.println("fanon : ");
  digitalWrite( Motor_M1, HIGH);
   
}
void fanoff(byte flag, byte numOfValues)
{
  Serial.println("fanoff : ");
  digitalWrite( Motor_M1, LOW);
   
}

兩組程式碼結合後
紅外線卻失效了 求解



发表于 2013-11-16 01:25 | 显示全部楼层
开关不用弄那么复杂
 楼主| 发表于 2013-11-16 19:41 | 显示全部楼层
兩組分開可以用  但是結合後卻不能用
是語法錯誤嗎?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2025-1-1 18:55 , Processed in 0.075800 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表