Antes de começar a ler este artigo recomendo que veja o artigo anterior, onde se utilizou a porta paralela para fazer ligar um LED.
Hoje vou alterar o protejo “Controlando LED com a porta paralela” para acender e apagar o mesmo LED através de um botão(físico).

PARTE 1 – O Hardware.

Na ficha soldou-se um botão(normalmente aberto) nos pino “S6″(entrada) e “G2″(negativo), as cores não são importantes pois não têm posição(podem ser invertidas).
PARTE 2 – O Software.
O codigo LedBut_Proj.java :
import parport.ParallelPort;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class LedBut_Proj{
public static void main(String[] args){
ParallelPort lpt1 = new ParallelPort(0x378);
Boolean ligado = false;
Boolean butCarregado = false;
// Input
System.out.println("\nSair!!(Ctrl-Z)");
while(true){
if(lpt1.read() != 63 && butCarregado == true){
if(ligado){
// Liga o Led
lpt1.write(1);
System.out.print("** Led Ligado! ** " + "\r");
butCarregado = false;
} else {
// Desliga o Led
lpt1.write(0);
System.out.print("** Led Desligado! **" + "\r");
butCarregado = false;
}
} else if(lpt1.read() == 63 && butCarregado == false){
ligado = !ligado;
butCarregado = true;
}
}
}
}
Notas Finais
Este artigo pode conter alguns erros, sugestões e/ou comentários são sempre bem vindos. Obrigado
