Hi. Again.
I have written a simple PIR library for Maple. Handling PIRs is easy, with this library.. It is even easier..
Check the example for usage..
Hi. Again.
I have written a simple PIR library for Maple. Handling PIRs is easy, with this library.. It is even easier..
Check the example for usage..
jake1981 - I had a quick look at your library.
IMHO it is good form to acknowledge the authors work that is used as a basis for new work.
I assume it is http://playground.arduino.cc/Code/PIRsense
IMHO you should also say what the copyright status of the code is.
I think it would be helpful for you to say which PIR sensor you have tested the code with. It looks like you might used something like the Parallax PIR sensor (e.g. at http://www.parallax.com/tabid/768/txtSearch/PIR+sensor/List/0/SortField/4/Default.aspx)
Those are different from a 'raw' PIR sensor, (e.g. http://uk.farnell.com/murata/ira-e712st3/pir-high-light-immunity/dp/1006207) which need a signal amplifier. So being clear is helpful.
How thoroughly do you understand the original code?
I ask because the code:
PIR::PIR(uint8 pin) {
_pin = pin;
pinMode(_pin, INPUT);
digitalWrite(_pin, LOW);
// ...
makes sense on an Arduino, but is a odd for an STM32.
The statement pinMode(_pin, INPUT);
sets the pin to be an input.
So the statement digitalWrite(_pin, LOW);
is strange, without an explanation, because normally code wouldn't write to an input pin.
However, on an Arduino (ATmega168/328), that sequence ensures the I/O ports pull-up resistor for that pin is off.
On Maple that pinMode(_pin, INPUT);
is sufficient, or you could say pinMode(_pin, INPUT_FLOATING);
(which is the same) if you wanted to be explicit about the pull-up/pull-down resistors.
IMHO the logic of the PIR class is unnecessarily complicated.
It might be simpler to either have:
a) a function which blocks until the sensor calibration time has passed (probably not ideal as the Parallax data sheet says this could be 60 seconds, but workable), or
b) a function which itself returns true once the calibration time for the PIR has elapsed. For example, set the variable calibrationTime = millis() + actual calibration time in the constructor, then put the first-time calibration logic in a renamedcalibrating
(is_calibrated?), and there is no need to call updating
. Just ask for the state of the PIR pin.
It also isn't clear that the concept of waiting for a period of time is completely implemented in the PIR. It seems to be divided between the demo program and the PIR class. If the _state variable, and all methods that use it are removed from the PIR class, then the PIR class becomes simpler, and the demo program seems simple too. Or move all the logic into the PIR class, and have it solve that part f the use case.
A small point. Code like this:
boolean PIR::calibrating(void) {
if ( calibrationTime == 0 )
return false;
return true;
}
May be simpler as:
boolean PIR::calibrating(void) {
return (calibrationTime != 0);
}
Just my $0.02. HTH
Thanks. Don't know if it speeds up a anything, but shorter source is always good.. I'll fix this later..
I'll update the library when I've got some time. But let's get to the answers;
What is my work based on? It is not based on that source, it's based on some other
source that I unfortunately cannot remember Where it located on the internet - but I chose
That one Because it was more informative than arduino pirsense doc. If I remember correctly,
It was on instructables.com
My license will be updated to readme. It will be public domain.
Yes, the device I used was the cheapest parallax type sensor I found from the ebay. Same sensors are sold also at electrodragon.com
Idea in my library is to record if there has been movement, that's why I wrote it that way, as project I plan to use this doesn't necessarily need the value all the time, but on a request; it needs to know if there has been activity..
And sorry about that digitalwrite low, I haven't readed all the docs and thought it couln't hurt. I'll add a ifdef arduino to that code..
Updates made - I also updated all my other libraries. Now licenses are mentioned.
You must log in to post.