from pymata4 import pymata4
import time
segPins = [3, 4, 5, 6, 7, 8, 9]
digPins = [10, 11, 12, 13]
lookupDictionary = {
"0": "1111110",
"1": "0110000",
"2": "1101101",
"3": "1111001",
"4": "0110011",
"5": "1011011",
"6": "1011111",
"7": "1110000",
"8": "1111111",
"9": "1111011",
"A": "1110111",
"B": "0011111",
"C": "1001110",
"D": "0111101",
"E": "1001111",
"F": "1000111"
}
trafficLightMapping = {
1: "A001",
2: "B002",
3: "C003",
4: "D004",
5: "E005",
6: "F006"
}
stage_durations = {
1: 5,
2: 3,
3: 3,
4: 5,
5: 3,
6: 3
}
def pin_setup(board):
for pin in segPins + digPins:
board.set_pin_mode_digital_output(pin)
def write_digit(board, message):
for digit_index, digit in enumerate(message):
for d in digPins:
board.digital_write(d, 1)
for segment_index, segmentPin in enumerate(segPins):
board.digital_write(segmentPin, lookupDictionary[digit][segment_index])
board.digital_write(digPins[digit_index], 0)
time.sleep(0.000001)
for d in digPins:
board.digital_write(d, 1)
for segment_pin in segPins:
board.digital_write(segment_pin, 1)
def main():
board = pymata4.Pymata4()
pin_setup(board)
for stage in trafficLightMapping:
write_digit(board, trafficLightMapping[stage])
time.sleep(stage_durations[stage])
if __name__ == "__main__":
main()
so i am trying to display these four digit values on my seven segment display (each value is in the trafficLightMapping dictionary) such that each digit is displayed for a certain period of time (time values are specified in the dictionary below.) stage one should display ‘A001’ onto the display for 5 seconds, stage two should display ‘B002’ for 3 seconds and so on. however when i run the code, the displays light up for less than a second and they do not display the actual 4 digits of each stage. random segments of each digit light up for less than a second, then the display goes blank for the specified time period, then it moves to the next stage. how do i fix it so that the four digits are displayed for each stage, for the time period i need them to be shown for.