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

<script >

function high(salida) { 
	var c;//c almacena el color del led
	
	if(salida<=3){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);
		
	}	
		
	
	

				
}

function bucle( numero, estado){//esta función se comporta como un bucle infinito sobre la función entrada()
	
	setInterval('entrada('+numero+','+estado+')',tiempo);

}

function reinicio() {

document.location.href = document.location.href;

}
var corriendo=false;//esto es para evitar que responda a los botones mientras corre
function entrada(numero, estado) {
tiempo=0;
if (corriendo==false) {
	

	
corriendo = true;




	if ((numero==6)&&(estado==1)) {//código si se pulsa 6
	
for (i=0;i<8;i++) {
high(i)
pausa(500);
	
}
for (i=0;i<8;i++) {
low(i)
pausa(500);
	
}	
setTimeout('corriendo=false',tiempo);//hay que terminar con esto cada programa
	
	}

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

	}
	if ((numero==7)&&(estado==1)) {//código si se pulsa 7
	
	for (i=7;i>-1;i--) {
high(i)
pausa(500);
	
}
for (i=7;i>-1;i--) {
low(i)
pausa(500);
	
}	
setTimeout('corriendo=false',tiempo);//hay que terminar con esto cada programa
	}

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

	}

	}
	

}
</script>
</head>
<body >

<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>