Hi to all!
PLEASE HELP, _I am spending time looking the same code the whole day, but I just cannot recognize the bug. I wrote a library for IR sensor from Parallax. I combine C++ and C and I suppose the bug is in the syntax. I think the code should be understandable, but if any doubts, please ask me.
The actual problem is that the constructor of my SensIR doesn`t executes!
Thanks a lot for the help, which I need urgently:)
#ifndef SensIR_h
#define SensIR_h
#include "WConstants.h"
class SensIR{
private :
int myPin;// 0 - 13
int mode;//mode to detect weather the interrupt driven method is used (mode equals zero)
//or the pooling method (mode=1)for the detection of the movement
public:
//int status;// 0=no movement, 1=movement
SensIR(int signalPin);//user chooses the input pin (0-13)
SensIR();//INT1 on pin 3
int check();
};
#endif
And the cpp file:
#include "SensIR.h"
#include <avr/signal.h>
#include <avr/interrupt.h>
extern volatile int status;// 0 equals no motion, 1 equals a motion
int calibrationTime=30;
SensIR::SensIR(int signalPin){
myPin=signalPin;
mode=0;
pinMode(myPin, INPUT);
digitalWrite(myPin, LOW);
status=0;
for(int i = 0; i < calibrationTime; i++)
{
Serial.print(". ");delay(1000);}
Serial.print("done ");
}
SensIR::SensIR(){
mode=1;
status=0;
PORTD &= ~(1<<PD3);//Digital pin 3 as input with pull-low
DDRD &= ~(1<<PD3);
EIMSK |=(1<<INT1);
EICRA |=(1<<ISC10);
EICRA &= ~(1<<ISC11);//interrupt on any level change
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++)
{
Serial.print(". ");
delay(1000);}//Serial just to detect that it actually works
Serial.print("done ");
}
SIGNAL (SIG_INTERRUPT1){
char cSREG;
cSREG = SREG;
if (PORTD&(1<<PD3))
status=1;//motion
else
status=0;
SREG = cSREG;
}
int SensIR::check(){
if (mode == 0)// If I dont use interrupts
{
if (digitalRead(myPin)==HIGH)
status=1;
else
status=0;
return status;
}else{
return status;
}
}
And the simple scatch:
#include <SensIR.h>
int ledPin = 13;
SensIR a;
void setup()
{
pinMode(ledPin, OUTPUT);
beginSerial(9600);
Serial.print("something");
a= SensIR();//THIS NEVER EXECUTES!!!!!
}
void loop()
{
}