2929/* ******************************************************************************************************************
3030** Declare all program constants **
3131*******************************************************************************************************************/
32- const uint32_t SERIAL_SPEED = 9600 ; // Set the baud rate for Serial I/O //
33- const uint8_t GREEN_LED_PIN = 13 ; // Define the default Arduino pin //
34- const uint8_t INTERRUPT_PIN = 9 ; // VCNL4010 attached to this pin //
35- const uint8_t WAKE_UP_PIN = 7 ; // Pin used to wake up processor, //
32+ const uint32_t SERIAL_SPEED = 9600 ; // Set the baud rate for Serial I/O //
33+ const uint8_t GREEN_LED_PIN = 13 ; // Define the default Arduino pin //
34+ const uint8_t INTERRUPT_PIN = 9 ; // VCNL4010 attached to this pin //
35+ const uint8_t WAKE_UP_PIN = 7 ; // Pin used to wake up processor, //
36+ const uint8_t PERCENT_CHANGE = 10 ; // Trigger percent change //
3637 // see comments above regarding use //
3738/* ******************************************************************************************************************
3839** Declare global variables and instantiate classes **
3940*******************************************************************************************************************/
4041uint16_t Proximity_Value = 0 ; // Last displayed Proximity reading //
4142uint16_t Proximity_Delta = 0 ; // Difference between current & last//
4243VCNL4010 Sensor; // Instantiate the class //
43-
4444/* ******************************************************************************************************************
4545** Declare interrupt vector to jump to when the VCNL4010 triggers a pin change interrupt. Nothing is done here **
4646** apart from disabling the interrupt to prevent a race condition where the program jumps here constantly **
4747*******************************************************************************************************************/
4848void sleepVector (void ) {detachInterrupt (digitalPinToInterrupt (WAKE_UP_PIN));} // Detach interrupt immediately //
49-
5049/* ******************************************************************************************************************
5150** Method Setup(). This is an Arduino IDE method which is called upon boot or restart. It is only called one time **
5251** and then control goes to the main loop, which loop indefinately. **
@@ -76,14 +75,13 @@ void setup() { //
7675 false , // Nothing on Ambient light reading //
7776 true , // Interrupt on Proximity threshold //
7877 false , // Nothing on Ambient threshold //
79- ProximityReading * 9 / 10 , // Low value is 90% of first reading//
80- ProximityReading * 11 / 10 ); // High value is 110% of first value//
78+ ProximityReading * PERCENT_CHANGE / 100 , // Low value is 90% of first reading//
79+ ProximityReading * ( 100 +PERCENT_CHANGE) / 100 ); // High value is 110% of first value//
8180 Sensor.setProximityContinuous (true ); // Turn on continuous Proximity //
8281 Serial.println (F (" VCNL4010 initialized.\n\n " )); // //
8382 pinMode (WAKE_UP_PIN, INPUT); // Pin is attached to VCNL4010 INT //
8483 digitalWrite (WAKE_UP_PIN, HIGH); // Configure pull-up resistor //
8584} // of method setup() //----------------------------------//
86-
8785/* ******************************************************************************************************************
8886** This is the main program for the Arduino IDE, it is an infinite loop and keeps on repeating. **
8987*******************************************************************************************************************/
@@ -107,7 +105,7 @@ void loop() { //
107105 USBDevice.attach (); // Re-attach the USB port //
108106 Serial.begin (SERIAL_SPEED); // Start serial comms at set Baud //
109107 while (!Serial); // wait for Serial to initialize //
110- delay (2000 );
108+ delay (2000 ); // //
111109 #endif // ----------------------------------//
112110 Sensor.clearInterrupt (0 ); // Reset status on VCNL4010 //
113111 Serial.println (F (" Woke up, sensor movement detected" )); // Tell the world that we're awake //
0 commit comments