
How do you plan to solve it?
int ledPins[4] = {2,3,4,5}; // LEDs for binary display
int incButton = 6; // increment button
int decButton = 7; // decrement button
int counter = 0;
void setup()
{
for(int i=0;i<4;i++)
{
pinMode(ledPins[i], OUTPUT);
}
pinMode(incButton, INPUT_PULLUP);
pinMode(decButton, INPUT_PULLUP);
}
void loop()
{
// increment
if(digitalRead(incButton) == LOW)
{
counter++;
if(counter > 15)
counter = 0;
delay(200);
}
// decrement
if(digitalRead(decButton) == LOW)
{
counter--;
if(counter < 0)
counter = 15;
delay(200);
}
displayBinary(counter);
}
void displayBinary(int num)
{
for(int i=0;i<4;i++)
{
digitalWrite(ledPins[i], (num >> i) & 1);
}
}
/*Paste your code here*/