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 hour260
Constructing a matrix keyboard with two buttons

Things used in this project

Hardware components

PCBWay Custom PCB
PCBWay Custom PCB
×1
Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Push Button - UsinaInfo Store
×1
Jumper Wire - UsinaInfo Store
×1
Rotary Potentiometer 10kR - UsinaInfo Store
×1
LED 5mm - UsinaInfo Store
×1
9V 1A - Power Supply - UsinaInfo Store
×1
Breadboard - UsinaInfo Store
×1
Breadboard Power Supply 5V/3.3V - UsinaInfo Store
×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

56 projects • 115 followers
Hello, I'm Diego Moreira, founder of the Silícios LAB and I love program microcontrollers and works with electronic projects.
PCBWay

PCBWay

58 projects • 91 followers
We are a pcb prototype and assembly manufacturer to help creators build projects. As low as $5/10pcs and 3 days delivery time.

Comments