   Serial.println(tempAverage);
 }
 
+// read the joystick and save the value
+void handle_joystick() {
+
+  float a = analogRead(3);
+
+  a *= 5.0;
+  a /= 1024.0;
+  
+  Serial.print("Button read analog = ");
+  Serial.println(a);
+  if (a < 0.2) joystickVal = BUTTON_DOWN;
+  if (a < 1.0) joystickVal = BUTTON_RIGHT;
+  if (a < 1.5) joystickVal = BUTTON_SELECT;
+  if (a < 2.0) joystickVal = BUTTON_UP;
+  if (a < 3.2) joystickVal = BUTTON_LEFT;
+  else         joystickVal = BUTTON_NONE;
+}
+
+// Read the start button and update the state machine.
+// Possible states are START, RUNNING, STOP, and STOPPED.
+// The state is updated and the timer is incremented or
+// reset to zero, depending on state.
+void handle_start_button()
+
+  uint8_t ADCReading < ADCThreshold);
+
+  // if the input is HIGH, handle it as a START
+  if (ADCReading > ADCThreshold) {
+    if (status == START) {
+      status = RUNNING;
+      currTime = millis()-startTime;
+    }
+    else if (status == RUNNING) {
+      status = RUNNING;
+      currTime = millis()-startTime;
+    }
+    else if (status == STOP) {
+      status = STOPPED;
+      currTime = 0;
+    }
+    else { 
+      status = START;
+      currTime = 0;
+    }
+  }
+
+  // otherwise the input is LOW, handle it as a STOP
+  else {
+    if (status == START) {
+      status = STOP;
+      currTime = millis()-startTime;
+    }
+    else if (status == RUNNING) {
+      status = STOP;
+      currTime = millis()-startTime;
+    }
+    else if (status == STOP) {
+      status = STOPPED;
+      currTime = 0;
+    }
+    else { 
+      status = STOPPED;
+      currTime = 0;
+    }
+  }
+}
+
 // Poll each thermocouple value and get an average value.
 // Adjusting by 32 for each tempSensor value
 // eliminates the SPI disconnection.

  Serial.println("  1 ON");  
} 
 
uint8_t readButton(void) {
  float a = analogRead(3);
  
  a *= 5.0;
  a /= 1024.0;
  
  Serial.print("Button read analog = ");
  Serial.println(a);
  if (a < 0.2) return BUTTON_DOWN;
  if (a < 1.0) return BUTTON_RIGHT;
  if (a < 1.5) return BUTTON_SELECT;
  if (a < 2.0) return BUTTON_UP;
  if (a < 3.2) return BUTTON_LEFT;
  else return BUTTON_NONE;
}

int scan_button(int swButton)
{
  int ADCreading = analogRead(swButton);
//  Serial.println(ADCreading);
  if (ADCreading < ADCThreshold) 
         return (1);
  else   return (0);
}

void tempPrint()
{
  Serial.print("Current temperature F = ");

 
 We referenced code written by Limor Fried/Ladyada
 for Adafruit Industries under the MIT license.
 
 *******************************************/
  
