byte D1 = 2;
byte D2 = 3;
byte D3 = 4;
byte D4 = 5;
byte A = 6;
byte B = 7;
byte C = 8;
byte D = 9;
byte E = 10;
byte F = 11;
byte G = 12;
byte DP = 13; // decimal point
// Define the input pins for the 7-segment display segments.
const int segmentPins[] = {A, B, C, D, E, F, G, DP};
// Define the input pins for the 7-segment display digits.
const int digitPins[] = {D1, D2, D3, D4};
// For common cathode
uint8_t digitON = LOW;
uint8_t digitOFF = HIGH;
uint8_t segmentON = HIGH;
uint8_t segmentOFF = LOW;
void setup() {
// Pin initialization.
for (int i = 0; i < 8; i++) {
pinMode(segmentPins[i], OUTPUT);
}
for (int i = 0; i < 4; i++) {
pinMode(digitPins[i], OUTPUT);
digitalWrite(digitPins[i], digitOFF);
}
}
void loop()
{
digitalWrite(D1, digitON); // Turn on the first digit
digitalWrite(D2, digitON); // Turn on the first digit
digitalWrite(D3, digitON); // Turn on the first digit
digitalWrite(D4, digitON); // Turn on the first digit
digitalWrite(B, segmentON);
digitalWrite(C, segmentON);
}