#include <LiquidCrystal_I2C.h>
int ledPin[]={7,8,9,10};
LiquidCrystal_I2C lcd_1(0x27, 16, 2);
void setup() {
// put your setup code here, to run once:
for (int i=0;i<4;i++){
pinMode(ledPin[i], OUTPUT);
}
lcd_1.init();
lcd_1.setBacklight(1);
lcd_1.setCursor(4,0);
lcd_1.print("in binary is");
}
void loop() {
// put your main code here, to run repeatedly:
for (int x =0;x<16;x++)
{
lcd_1.clear();
lcd_1.setCursor(0,0);
lcd_1.print(x);
lcd_1.print(" in binary is");
displayBinary(x);
delay(1000);
}
}
void displayBinary(byte numToShow)
{
for (int i =0;i<4;i++)
{
lcd_1.setCursor(i,1);
if (bitRead(numToShow, i)==1)
{
digitalWrite(ledPin[i], HIGH);
lcd_1.setCursor(3-i,1);
lcd_1.print(1);
}
else
{
digitalWrite(ledPin[i], LOW);
lcd_1.setCursor(3-i,1);
lcd_1.print(0);
}
}
}