由于添加了故障安全功能,代码无法正常运行

时间:2018-09-20 10:25:16

标签: arduino

我一直在忙着编写一个arduino代码,该代码使用基于PIR传感器的IR打开和关闭屏幕。在我添加额外的代码以阻止设备每次从PIR传感器获得输入时都停止发送IR信号之前,该设备一直在工作。我是以“ counterSensor”的形式完成的,您可以在下面的代码中找到。

自从我添加计数器以来,我的设备不再发送IR信号。我尝试查找任何硬件故障(我更换了IR指示灯,并使用普通的蓝色指示灯对其进行了测试。两次均无效)。我还尝试使用IR库中的示例代码,该代码应该可以正常工作,但是我什么也没得到。

我也在另一种arduino上尝试了所有这些方法,但是对该arduino也没有任何作用。

有人可以帮我吗?

提前谢谢!

代码:

/*
--- Code Geschreven door Julian Berendsen.
--- Code geschreven voor: Fidato 

Toelichting:

Deze code is bedoeld voor een device dat ik heb gemaakt wat een tv scherm aan 
en uit zet zodra er mensen in een ruimte komen. Ik heb dit device gemaakt als 
project dat ik tijdens mijn stage periode bij Fidato heb gemaakt.
*/

 #include <IRremote.h>
 IRsend irsend;


 #define sensorPin 4
#define switchPin 5

int sensorState= 0;
int switchState = 0;
int counterSensor= 0;

void setup() {
pinMode(sensorPin,INPUT);
pinMode(switchPin, INPUT);
Serial.begin(9600);
}

void loop() {
delay(3000);
 Serial.println(counterSensor);

sensorState = digitalRead(sensorPin);
switchState = digitalRead(switchPin);

if(switchState == HIGH){
Serial.println("System Active");

  if( sensorState == HIGH){
    counterSensor++;

       if(counterSensor >= 2 && counterSensor <= 5){
          tvOn();   
     }
  }
 }

  if( sensorState == LOW){
    counterSensor--;

     if(counterSensor <= -2 && counterSensor >= -5){
      tvOff();
  }

  if (counterSensor >= 15){
     counterSensor = 10;
  }

  if (counterSensor <= -15){
       counterSensor = -10;
  }

if(switchState == LOW){
  counterSensor =0;
  Serial.println("System inactive");
 }}}


/*Void used for sending the IR On signal to the screen:  */
void tvOn(){
    Serial.println("Turning screen on...");
    // Initializes the frequency and signal bursts of the IR remote
  int khzON = 38; // 38kHz carrier frequency for the NEC protocol
  unsigned int irSignalON[] = {9024 ,4512 ,564 ,564 ,564 ,564 ,564 ,1692 ,564 
,564 ,564 ,564 ,564 ,564 ,564 ,564 ,564 ,564 ,564 ,1692 ,564 ,1692 ,564 ,564 
,564 ,1692 ,564 ,1692 ,564 ,1692 ,564 ,1692 ,564 ,1692 ,564 ,564 ,564 ,564 
,564 ,1692 ,564 ,564 ,564 ,564 ,564 ,564 ,564 ,1692 ,564 ,1692 ,564 ,1692 
,564 ,1692 ,564 ,564 ,564 ,1692 ,564 ,1692 ,564 ,1692 ,564 ,564 ,564 ,564 
,564 ,39756}; //AnalysIR Batch Export (IRremote) , RAW
  // Sends the IR signal
  irsend.sendRaw(irSignalON, sizeof(irSignalON) / sizeof(irSignalON[0]), 
khzON); //Note the approach used to automatically calculate the size of the 
array.


  delay(3000);
}

/* Void used for sending the IR off signal to the screen:  */
void tvOff(){
Serial.println("Turning screen off...");
 // Initializes the frequency and signal bursts of the IR remote
int khzOFF = 38; // 38kHz carrier frequency for the NEC protocol
unsigned int irSignalOFF[] = {9024 ,4512 ,564 ,564 ,564 ,564 ,564 ,1692 ,564 
,564 ,564 ,564 ,564 ,564 ,564 ,564 ,564 ,564 ,564 ,1692 ,564 ,1692 ,564 ,564 
,564 ,1692 ,564 ,1692 ,564 ,1692 ,564 ,1692 ,564 ,1692 ,564 ,1692 ,564 ,564 
,564 ,1692 ,564 ,564 ,564 ,564 ,564 ,564 ,564 ,1692 ,564 ,1692 ,564 ,564 ,564 
,1692 ,564 ,564 ,564 ,1692 ,564 ,1692 ,564 ,1692 ,564 ,564 ,564 ,564 ,564 
,39756}; //AnalysIR Batch Export (IRremote) , RAW
// Sends the IR signal
irsend.sendRaw(irSignalOFF, sizeof(irSignalOFF) / sizeof(irSignalOFF[0]), 
 khzOFF); //Note the approach used to automatically calculate the size of the 
array.
delay (3000);
}

0 个答案:

没有答案