A micropython library for controlling 1 to 4 digit Seven segment display.
This MicroPython module simplifies working with seven-segment displays on different microcontroller boards. It's compatible with 1 to 4 digit displays and has been thoroughly tested on ESP32 with a 4-digit seven-segment display, ensuring easy integration and reliable performance for your projects.
Scroll down for installation steps 👇
Link of this simulation: wokwi esp32 (In the simulation, wait for 20-30 seconds for setting up the connection)
Connect pins like this☝️ This is an example code for a 30 second timer using a common anode 4 digit display :
import micropython_7seg
segments=micropython_7seg.Sevseg("anode")
segments.anode(13,27,14,12) #Change the values according to your connection
segments.cathode(15,2,19,4,21,5,18)
segments.count_down(30)
Use mip (Micropython package manager) to install this module by importing mip in your micropython interpreter.
mpremote install github:AthulNoobie/micropython_7segment_display_library
or
import mip
mip.install("github:AthulNoobie/micropython_7segment_display_library")
import micropython_7seg
#After importing the module, create an object called "segments"(You can give any name).
segments = micropython_7seg.Sevseg("anode")
#Enter "cathode" if you are using a common cathode display.
If you are using a common anode display, The anodes are controlling the digits and cathodes are controlling the segments. It is vice versa in common cathode display.
segments.anode(digit4_pin, digit3_pin, digit2_pin, digit1_pin)
#Anode configuration
segments.cathode(A-pin, B-pin, C-pin, D-pin, E-pin, F-pin, G-pin)
#Cathode configuration
segments.cathode(digit4_pin, digit3_pi, digit2_pin, digit1_pin)
#Cathode configuration
segments.anode(A-pin, B-pin, C-pin, D-pin, E-pin, F-pin, G-pin)
#Anode configuration
segments.display(2024)
#This will display the digit 2024
You can use the count_down() method for both count down and count up.
Default function of count_down() is decrementing the input with a delay of 1 second. But you can modify it:
count_down(initial,final=0,delay=1, decrement=-1,flicker=0.005).This is the default structure.
segments.count_down(30)
#This will do a countdown from 30 to 0.
segments.count_down(30,20,1,-2)
#This will do a cout_down from 30 to 20 by decrementing 2 with a delay of 1 sec. Like this:
30,28,26,24,22,20
Use the decrement as 1 for count up and -1 for count down.
segments.count_down(30,41,1,1)
#This will do a count up from 30 to 40