Now the only thing left to do is turn the right anode on and we have one of our 7-segments light up.
This function requires us to give it 3 arguments: The Decimal value of the number that needs to be displayed (same as previous function), the state of the Decimal Point and witch digit needs to be lit up. This can only be a number from 1 to 4 or else it gives a value error back.
This is done by calling the previous SetDigits function with the right arguments and witch
The DisplayDigit function
So now we need 2 more functions, the first one is a delay, the seccond one controls if the leds between the 2 displays are on or off.
The delay function is easy it's just a time.sleep(). But to use this function we need another library, It's called time.
The DisplayLeds function is also pretty easy it just gets a boolean that turns the leds either on or off.
Delay and DisplayLeds Functions
The only thing left to do is to get the time and convert it into the right format.
To get the time we need to use the datetime library. It's as easy as "variableName = datetime.datetime.now()" and voilà now the variable has got the time and date in it.
Then to get the hour and minutes out of it we can simply do "variableName.hour" or "variableName.minute" to get the minutes or hours.
Then we need to split the hours or minutes in single digits.
For that we have to use the math library to round the numbers down.
And to get the first digit of either the hours of minutes we can do something like this: "hour10 = maht.floor(hour / 10)" this gives a number back that is the first digit of the hour.
(It divides the hours variable by 10 and then rounds that number down)
To do the same thing with the last digit of hours we can do this "hour1 = hour % 10" .
(It gives the remainder of the hours divided by 10)
Then to turn the Leds on or of we have to see if the secconds are devideable by 2 and if that is the case the variable Leds will be 1 (and turn on the leds).
And then we just have to return all the numbers we have calculated.
So we get a function that looks like this.