Implement a 4-bit binary counter

Solving Approach

How do you plan to solve it?

 
 step 1: declare pushbutton as input and led as ouput 

step 2:check button status 

 

 

 

Code

/*Paste your code here*/

#define Incbutton 8

#define Decbutton 9
int LED[4]={2, 3, 4, 5};
int counter =0,bit=0;

int status1=0,status2=0;

void setup()
{
pinMode(LED[4], OUTPUT);
pinMode(Incbutton, INPUT);
pinMode(Incbutton, INPUT);
   for(int i=0;i<4;i++){
    digitalWrite(LED[i],LOW);}
}

void loop()
{

status1=digitalRead(Incbutton);

status2=digitalRead(Decbutton);
if(status1==HIGH ){
  counter=counter+1;
  for(int i=0;i<4;i++){
  bit=counter<<1;
    digitalWrite(LED[i],bit);}
}

if(status2==HIGH){
 counter=counter-1;
  for(int i=0;i<4;i++){
  bit=counter<<1;
    digitalWrite(LED[i],bit);}
}
  
}

Output

Video

Add a video of the output (know more)

 

 

 

 

 

 

 

 

 

Upvote
Downvote

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!