//https://wokwi.com/projects/404319764122332161
//https://dronebotworkshop.com/led-displays/
// Include library
#include "SevSeg.h"
// Create object
SevSeg SevSegD1;
SevSeg SevSegD2;
// Number of digits in display 1
byte numDigitsD1 = 1;
// Display select pins (not used with single display)
byte digitPinsD1[] = {};
// Display segment pins A, B, C, D, E, F, G,DP -DP Not used
byte segmentPinsD1[] = {6, 5, 2, 3, 4, 7, 8};
// Dropping resistors used
bool resistorsOnSegmentsD1 = true;
// Display type
byte hardwareConfigD1 = COMMON_ANODE;
// updateWithDelays Default 'false' is Recommended
bool updateWithDelaysD1 = false;
//leadingZeros Use 'true' if you'd like to keep the leading zeros
bool leadingZerosD1 = false;
// Use disableDecPoint 'true' if your decimal point doesn't exist or isn't connected. Then, you only need to specify 7 segmentPins[]
bool disableDecPointD1 = true;
//The analog input pins can be used as digital pins,
//referred to as A0, A1, etc. The exception is the
//Arduino Nano, Pro Mini, and Mini’s A6 and A7 pins,
//which can only be used as analog inputs.
// Number of digits in display 2
byte numDigitsD2 = 1;
// Display select pins (not used with single display)
byte digitPinsD2[] = {};
// Display segment pins A, B, C, D, E, F, G,DP -DP Not used
byte segmentPinsD2[] = {A1, A0, 11, 12, 13, A2, A3};
// Dropping resistors used
bool resistorsOnSegmentsD2 = true;
// Display type
byte hardwareConfigD2 = COMMON_ANODE;
// updateWithDelays Default 'false' is Recommended
bool updateWithDelaysD2 = false;
//leadingZeros Use 'true' if you'd like to keep the leading zeros
bool leadingZerosD2 = false;
// Use disableDecPoint 'true' if your decimal point doesn't exist or isn't connected. Then, you only need to specify 7 segmentPins[]
bool disableDecPointD2 = true;
//Inputs
const int rearInput = 10; // the number of the TC Rear in
const int frontInput = 9; // the number of the TC Front in
int rearInputState = 0; // variable for reading the TC Rear status
int frontInputState = 0; // variable for reading the TC Front status
void setup() {
// Start display 1 object
SevSegD1.begin(hardwareConfigD1, numDigitsD1, digitPinsD1, segmentPinsD1, resistorsOnSegmentsD1, updateWithDelaysD1, leadingZerosD1, disableDecPointD1);
// Set brightness
SevSegD1.setBrightness(90);
// Start display 2 object
SevSegD2.begin(hardwareConfigD2, numDigitsD2, digitPinsD2, segmentPinsD2, resistorsOnSegmentsD2, updateWithDelaysD2, leadingZerosD2, disableDecPointD2);
// Set brightness
SevSegD2.setBrightness(90);
// initialize the TC Rear in pin as an input:
pinMode(rearInput, INPUT_PULLUP);
// initialize the TC Rear in pin as an input:
pinMode(frontInput, INPUT_PULLUP);
}
void loop() {
// read the state of the TC Rear Input :
rearInputState = digitalRead(rearInput);
// read the state of the TC Front Input :
frontInputState = digitalRead(frontInput);
//If D1 is refeshed 1st, the D1 A Seg Flashes When DP is not
//Defined
SevSegD2.refreshDisplay();
SevSegD1.refreshDisplay();
// check if the Front Input is active. If it is, the FrotInputState is HIGH:
if (frontInputState == HIGH) {
//Set Display 1 to "2":
SevSegD1.setNumber(2);
} else {
// Set Display 1 to "4":
SevSegD1.setNumber(4);
}
// check if the Rear Input is active. If it is, the rearInputState is HIGH:
if (rearInputState == HIGH) {
//Set Display 1 to "H":
SevSegD2.setChars("H");
} else {
// Set Display 1 to "L":
SevSegD2.setChars("L");
}
//delay(1000);
//SevSegD1.refreshDisplay();
delay(500);
}