<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>ej 1</title>
<style type="text/css">
td {
	text-align: center;
}
</style>

<script >

function high(salida) { 
	var c;//c almacena el color del led
	
	if(salida<=7){c = "#ff0000";
		}else {
		c = "#00ff00";}
	setTimeout('document.getElementById(' + salida + ').style.background ="'+ c+ '"',tiempo);	
}
  		
 function low(salida) { 
 	setTimeout('document.getElementById(' + salida + ').style.background ="#FFFFFF"',tiempo);	
 
}

var tiempo = 0;

function pausa(milisegundos) {
	tiempo = tiempo + milisegundos;
}

var tiempoDp;//almacena el tiempo que tarda p() en ejecutarse

function p() {//aquí debemos escribir el programa que se repite una sola vez
	var tInicio// almacena el momento de inicio de p
	var d = new Date();
	tInicio = d.getTime();
	for (i=1;i<=5;i++) {
		high(i);
		
	}	
		
	
	
	tiempoDp = d.getTime() - tInicio;
				
}

function bucle(){//esta función se comporta como un bucle infinito sobre la función p()
	p();
	setInterval('p()',tiempoDp);

}

function entrada(numero, estado) {

	if ((numero==6)&&(estado==1)) {//código si se pulsa 6
		
	high(6);

	
	}

	if ((numero==6)&&(estado==0)) {//código si se libera 6
		
	low (6);

	}
	if ((numero==7)&&(estado==1)) {//código si se pulsa 7
	
	
	}

	if ((numero==7)&&(estado==0)) {//código si se libera 7
	
	
	}
	
}


</script>
</head>
<body onload="entrada(6,0);entrada(7,0)">

<td bgcolor="#FF0000"></td>
<table cellpadding="2" cellspacing="2" border="1">
	<tr>
		<td id="7">7</td>
		<td id="6">6</td>
		<td id="5">5</td>
		<td id="4">4</td>
		<td id="3">3</td>
		<td id="2">2</td>
		<td id="1">1</td>
		<td id="0">0</td>
		
	</tr>
	
</table>
<br>
<input type="submit" value="entrada 6" onmousedown='entrada(6,1)' onclick='entrada(6,0)'/>
<input type="submit" value="entrada 7" onmousedown='entrada(7,1)' onclick='entrada(7,0)'/>
</body>
</html>