byte D1 = 0;
byte D2 = 3;
byte D3 = 4;
byte D4 = 7;
byte A = 1;
byte B = 5;
byte C = 9;
byte D = 10;
byte E = 11;
byte F = 2;
byte G = 8;
byte DP = 6; // 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;*/
//https://softwareparticles.com/learn-how-a-4-digit-7-segment-led-display-works-and-how-to-control-it-using-an-arduino/*/
//https://softwareparticles.com/learn-how-a-4-digit-7-segment-led-display-works-and-how-to-control-it-using-an-arduino/
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()
{
/*// ===== First Digit =====
// We iterate through each of the segments of the first digit.
for (int i = 0; i < 7; i++){
// we access the bits of the binary number 0b01100000, which corresponds to the segments A, B, C, D, E, F, and the decimal point (DP).
digitalWrite(segmentPins[i], bitRead(0b01100000, 7 - i) == 1 ? segmentON : segmentOFF);
// We use the bitRead() function to get the i-th bit, and if it is equal to 1, we set the segment to segmentON, otherwise we set it to segmentOFF.
}
digitalWrite(D1, digitON); // We turn on the D1 input to display the first digit.
delay(10); // We add a delay to control the brightness of the digit.
// ===== Second Digit =====
digitalWrite(D1, digitOFF); // We turn off the D1 input.
// We iterate through each of the segments of the second digit. We use the same approach as before to set the appropriate segments for the number '2'
for (int i = 0; i < 7; i++){
digitalWrite(segmentPins[i], bitRead(0b11011010, 7 - i) == 1 ? segmentON : segmentOFF);
}
digitalWrite(D2, digitON); // We turn on the D2 input to display the second digit.
delay(10); // We add another delay to control the brightness.
digitalWrite(D2, digitOFF); // We turn off the D2 input and repeat the process again.*/
digitalWrite(D1, HIGH);
digitalWrite(DP, HIGH);
}