 	// turn on pullup resistor
 	digitalWrite(pushButton, HIGH);
 
-	// output LED ports
-	pinMode(switchLed, OUTPUT); 
+	// output port for LED
 	pinMode(mainLed, OUTPUT); 
 }
 
 void loop(){
+	int serialRead = -1;
+
 	if (Serial.available() > 0) {
 		// read over serial port
-		int serialRead = Serial.read();
+		serialRead = Serial.read();
 
 		// set LED on/off from serial
 		if(serialRead == ON) {

int pushButton = 2;
int switchLed = 13;
int mainLed = 6;

int switchState = 1;

#define ON 49	// 1
#define OFF 48	// 0

			digitalWrite(mainLed, 0);
		}

		noSerialCount = 0;
	}else{
		noSerialCount += 1;

		// if no serial input for 1 second, switch off LED
		if(noSerialCount == 5) {
			digitalWrite(mainLed, 0);
		}
	}

	// check for button press
	int sensorRead = digitalRead(pushButton);

	if(switchState != sensorRead) {
		switchState = sensorRead;

		// send on serial when switch pushed
		if(sensorRead == 0) {
			Serial.println(serialRead);
		}
	}

	// introduce a sensible delay
	delay(100);
}
