const int segA = 6;
const int segB = 5;
const int segC = 4;
const int segD = 3;
const int segE = 2;
const int segF = 1;
const int segG = 0;
const int led1 = 8;
const int led2 = 9;
unsigned char tab_segmen[10] =
{0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
// 0 1 2 3 4 5 6 7 8 9
void seg_out(unsigned char a) {
unsigned char b,c;
b = tab_segmen[a];
c = (b >> 0) & 1;
digitalWrite(segA, c);
c = (b >> 1) & 1;
digitalWrite(segB, c);
c = (b >> 2) & 1;
digitalWrite(segC, c);
c = (b >> 3) & 1;
digitalWrite(segD, c);
c = (b >> 4) & 1;
digitalWrite(segE, c);
c = (b >> 5) & 1;
digitalWrite(segF, c);
c = (b >> 6) & 1;
digitalWrite(segG, c);
}
void setup() {
// put your setup code here, to run once:
pinMode(segA, OUTPUT);
pinMode(segB, OUTPUT);
pinMode(segC, OUTPUT);
pinMode(segD, OUTPUT);
pinMode(segE, OUTPUT);
pinMode(segF, OUTPUT);
pinMode(segG, OUTPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
seg_out(1); // menampilkan angka 1
digitalWrite(led1, 1);
delay (30);
digitalWrite(led1, 0);
delayMicroseconds(100);
seg_out(2); // menampilkan angka 2
digitalWrite(led2, 1);
delay (30);
digitalWrite(led2, 0);
delayMicroseconds(100);
}