Silícios LabPCBWay
Published © GPL3+

Constructing a matrix keyboard with two buttons

In this project, you'll learn how make a matrix keyboard using only one button.

BeginnerProtip1 hour687
Constructing a matrix keyboard with two buttons

Things used in this project

Hardware components

PCBWay Custom PCB
PCBWay Custom PCB
×1
Arduino UNO R3 - UTSOURCE
×1
Micro Switch 6x6x5 - UTSOURCE
×1
Jumper Wire - UTSOURCE
×1
Rotary Potentiometer 10kR - UTSOURCE
×1
LED 5mm - UTSOURCE
×1
Power Supply 9V/2A - UTSOURCE
×1
Protoboard - UTSOURCE
×1
Breadboard Power Supply - UTSOURCE
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Button like a matrix keyboard

Arduino
int botao_inc = 0;
int estadoInc = 0;

int cont = 0;

void setup() 
{

  pinMode(10, INPUT); //Botão de Incremento
  pinMode(5, OUTPUT); //LED1
  pinMode(6, OUTPUT); //LED2
  pinMode(7, OUTPUT); //LED3
  pinMode(8, OUTPUT); //LED4

}

void loop() 
{

  botao_inc = digitalRead(10);

  delay(10);
//---------------------Leitura dos estados do botão de incremento-----------------------/

  if(botao_inc == 0 && estadoInc == 1)
  {
    estadoInc = 0;
  }
  
  if(botao_inc == 1 && estadoInc == 0)
  {  
    cont++;
    estadoInc = 1;
  }

  

//-------------------------------------------------------------------------------------------------------/

//-----------------------------------------Acionamento dos LEDs------------------------------------------/

if(cont > 4)
{
cont = 0;  
}



if(cont == 0)
{
digitalWrite(5, LOW);  
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}

if(cont == 1)
{
digitalWrite(5, HIGH);  
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}

if(cont == 2)
{
digitalWrite(5, HIGH);  
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
}

if(cont == 3)
{
digitalWrite(5, HIGH);  
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
}

if(cont == 4)
{
digitalWrite(5, HIGH);  
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}
//-------------------------------------------------------------------------------------------------------/
}

Credits

Silícios Lab

Silícios Lab

72 projects • 173 followers
Hello, I love program microcontrollers and works with electronic projects.
PCBWay

PCBWay

90 projects • 146 followers
We are a PCB and assembly manufacturer, As low as $5/10pcs and 24 hours delivery time. We are committed to helping creators build project.

Comments