 {
   now = millis();
 
-  //Checked the state of the button.
+  /*
+   * Check the state of the button.
+   */
   boolean buttonPushed = false;
   int buttonNow = digitalRead(BUTTON_PIN);
   if (buttonNow != buttonThen && buttonNow)
   {
     //Button pushed!
-    buttonPushed = true;
+     buttonPushed = true;
   }
-
   buttonThen = buttonNow;
-
-
-  //Act based on current state.
+  
+  
+  /*
+   * Check for a rising edge on the sensor.
+   */
+  boolean sensorRising = false;
+  int sensorNow = digitalRead(SENSOR_PIN);
+  if (sensorNow != sensorThen && sensorNow)
+  {
+    //Sensor rising edge!
+    sensorRising = true;
+  }  
+  sensorThen = sensorNow;
+
+
+  /*
+   * Act based on current state.
+   */
   switch (currentState)
   {
 

    digitalWrite(RED_LED_PIN, HIGH);
    digitalWrite(GREEN_LED_PIN, LOW);

    if (digitalRead(SENSOR_PIN))
    {
      Serial.println("Movement!");
      currentState = S_ACTIVE; 

unsigned long now = 0;

int buttonThen;
int sensorThen;
boolean wasHigh = false;

///SETUP//////////////////////////////////////////////////////////////////
