Testing the photoresistor with software
We will be using the arduPi
template we installed earlier to create our test code.
Take a copy of arduPi_template.cpp
and rename it as LightSensor.cpp
.
Next, in a text editor of your choice, open the new file and add the following code to it:
//Include ArduPi library #include "arduPi.h" //Include the Math library #include <math.h> #define TH 690
Here, we had the standard template header, but we also added a new constant called TH
. This will represent the threshold. Like the setpoint constant we declared for the thermostat, the threshold is used to decide to perform an operation based upon whether the room gets lighter or darker.
Let's move on to add the next block of code. Paste this block after the previous code you added to your file:
/********************************************************* * IF YOUR ARDUINO CODE HAS OTHER FUNCTIONS APART FROM * * setup() AND loop() YOU MUST DECLARE THEM HERE * * ********************************...