  * @return Integer
  */
 int readSensor(int sensorPin, int min, int max) {
-
-	int average;
-	float sensorValue, sum;
+	int sensorValue, average;
+	float sum;
 	for (int i = 0; i < 50; i++) {
 		sensorValue = analogRead(sensorPin);
 		sum += sensorValue;

	average = (int)(sum/50.0);

	// limit sensor reading between min & max calibration values
	average = min(average, max);	// min: the smaller of two numbers
	average = max(average, min);	// max: the bigger of two numbers

	return constrain(average, min, max);
}

void doUpdate() {
	int newLedLevel;
	// read the value from the sensor:
	sensorValue = readSensor(MOISTURE_SENSOR_PIN, MOISTURE_LEVEL_MIN, MOISTURE_LEVEL_MAX);
	brightnessValue = readSensor(PHOTORESISTOR_PIN, 0, 1024); //

	// sensor values are reversed (bigger value is dry and smaller value is moist)
	newLedLevel = map(sensorValue, MOISTURE_LEVEL_MIN, MOISTURE_LEVEL_MAX, 255, 1);

	// update if the value changes
	if (ledLevel != newLedLevel) {
