NodeManager Motion Sensor: how to use the SensorSwitch class?
-
Sorry for the delay guys, for some reasons I haven't got the notification of this thread, thanks @gohan for pulling me in! When using SENSOR_MOTION, the default mode is already RISING. To help you reading through the code, the registerSensor() in NodeManager.cpp would create an instance of the SensorMotion class. SensorMotion is derived from SensorSwitch (which has CHANGE has default mode) but in its constructor (SensorMotion::SensorMotion) you will find a setMode(RISING) which is then the default value.
Whatever parameter you want to change, this requires three steps:
- registering the sensor
- retrieving the instance of the class
- invoking its functions
SensorSwitch in your example above is a class, you need the instantiated object to invoke its member functions. So something like the following:
// register the sensor and keep track of its id int sensorPIR = nodeManager.registerSensor(SENSOR_MOTION,3); // retrieve the instance of the object. Since getSensor() will return a generic Sensor class, you need to cast it accordingly SensorMotion* sensorMotion = (SensorMotion*)nodeManager.getSensor(sensorPIR_Id); // invoke whatever function you need. Since sensorMotion is a pointer, you need to use the -> notation sensorMotion->setMode(CHANGE); sensorMotion->setInitial(LOW);Does it make sense now?
Thanks -
Thank you very much sir, it start making sense to me, I still need to "digest" this :smile: as I am a HW engineer ... but trying to improve my SW skills.
I am comfortable with the basics of C and Arduino but not really with object oriented programming.
What literature would you suggest me to start with to understand this kind of coding? Java perhaps? -
Thank you very much sir, it start making sense to me, I still need to "digest" this :smile: as I am a HW engineer ... but trying to improve my SW skills.
I am comfortable with the basics of C and Arduino but not really with object oriented programming.
What literature would you suggest me to start with to understand this kind of coding? Java perhaps? -
Agree starting from c++ would make more sense :-) Just a silly personal advise: pay attention not to get lost into the tons of capabilities c++ can provide, especially if you want to be just focused on arduino to start with since you can easily get lost. Sometimes I personally prefer just an electronic one-pager with a good amount of examples :-)
-
I thought you may say that :smile: ... is there a good C++ book for beginners that you would recommend?
On paper I mean, that I can buy?