#include <Wire.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
byte segment[8][8] =
{
{ B01111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 },
{ B11111, B11111, B11111, B00000, B00000, B00000, B00000, B00000 },
{ B11110, B11111, B11111, B11111, B11111, B11111, B11111, B11111 },
{ B11111, B11111, B11111, B11111, B11111, B11111, B11111, B01111 },
{ B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111 },
{ B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11110 },
{ B11111, B11111, B11111, B00000, B00000, B00000, B11111, B11111 },
{ B11111, B00000, B00000, B00000, B00000, B11111, B11111, B11111 }
};
int col = 0;
int number;
void setup()
{
Wire.begin();
// Initializes the LCD
lcd.begin(16, 2);
// Associates each created segment with a number
for (byte i = 0; i < 8; i++) {
lcd.createChar(i, segment[i]);
}
}
void loop()
{
col=0;
digit8();
col=4;
digit7();
col=9;
digit6();
col=13;
digit5();
delay(1000);
}
void digit0() // Set the segments to the number 0
{
lcd.setCursor(col, 0); // Select the top line
lcd.write((byte)0); // Segment 0 selected
lcd.write(1); // Segment 1 selected
lcd.write(2);
lcd.setCursor(col, 1); // Select the bottom line
lcd.write(3);
lcd.write(4);
lcd.write(5);
}
void digit1() // Set the segments to the number 1
{
lcd.setCursor(col, 0);
lcd.write(1);
lcd.write(2);
lcd.setCursor(col + 1, 1);
lcd.write(5);
}
void digit2() // Set the segments to the number 2
{
lcd.setCursor(col, 0);
lcd.write(6);
lcd.write(6);
lcd.write(2);
lcd.setCursor(col, 1);
lcd.write(3);
lcd.write(7);
lcd.write(7);
}
void digit3() // Set the segments to the number 3
{
lcd.setCursor(col, 0);
lcd.write(6);
lcd.write(6);
lcd.write(2);
lcd.setCursor(col, 1);
lcd.write(7);
lcd.write(7);
lcd.write(5);
}
void digit4() // Set the segments to the number 4
{
lcd.setCursor(col, 0);
lcd.write(3);
lcd.write(4);
lcd.write(2);
lcd.setCursor(col + 2, 1);
lcd.write(5);
}
void digit5() // Set the segments to the number 5
{
lcd.setCursor(col, 0);
lcd.write((byte)0);
lcd.write(6);
lcd.write(6);
lcd.setCursor(col, 1);
lcd.write(7);
lcd.write(7);
lcd.write(5);
}
void digit6() // Set the segments to the number 6
{
lcd.setCursor(col, 0);
lcd.write((byte)0);
lcd.write(6);
lcd.write(6);
lcd.setCursor(col, 1);
lcd.write(3);
lcd.write(7);
lcd.write(5);
}
void digit7() // Set the segments to the number 7
{
lcd.setCursor(col, 0);
lcd.write(1);
lcd.write(1);
lcd.write(2);
lcd.setCursor(col + 1, 1);
lcd.write((byte)0);
}
void digit8() // Set the segments to the number 8
{
lcd.setCursor(col, 0);
lcd.write((byte)0);
lcd.write((byte)6);
lcd.write(2);
lcd.setCursor(col, 1);
lcd.write(3);
lcd.write(7);
lcd.write(5);
}
void digit9() // Set the segments to the number 9
{
lcd.setCursor(col, 0);
lcd.write((byte)0);
lcd.write((byte)6);
lcd.write((byte)2);
lcd.setCursor(col + 2, 1);
lcd.write((byte)5);
}
void showDigit() // Shows the number in the position defined by "X"
{
switch (number) {
case 0: digit0();
break;
case 1: digit1();
break;
case 2: digit2();
break;
case 3: digit3();
break;
case 4: digit4();
break;
case 5: digit5();
break;
case 6: digit6();
break;
case 7: digit7();
break;
case 8: digit8();
break;
case 9: digit9();
break;
}
}