From 04e96506401bda46fb7bd2e4800f21db29b3bcb7 Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Fri, 6 Oct 2023 01:51:55 +0530 Subject: [PATCH 01/17] Add files via upload --- electronics/wheatstone_bridge.py | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 electronics/wheatstone_bridge.py diff --git a/electronics/wheatstone_bridge.py b/electronics/wheatstone_bridge.py new file mode 100644 index 000000000000..02aa9f6e05f1 --- /dev/null +++ b/electronics/wheatstone_bridge.py @@ -0,0 +1,36 @@ +# https://en.wikipedia.org/wiki/Wheatstone_bridge +from __future__ import annotations + + +def wheatstone_solver( + resistance_1: float, resistance_2: float, resistance_3: float +) -> tuple: + """ + This function can calculate the unknown resistance in an wheatstone network. + + Usage examples: + >>> wheatstone_solver(resistance_1=2, resistance_2=4, resistance_3=5) + 10.0 + >>> wheatstone_solver(resistance_1=356, resistance_2=234, resistance_3=976) + 641.5280898876405 + >>> wheatstone_solver(resistance_1=2, resistance_2=-1, resistance_3=2) + Traceback (most recent call last): + ... + ValueError: All resistance values must be positive + >>> wheatstone_solver(resistance_1=0, resistance_2=0, resistance_3=2) + Traceback (most recent call last): + ... + ValueError: All resistance values must be positive + """ + + if resistance_1 <= 0 or resistance_2 <= 0 or resistance_3 <= 0: + raise ValueError("All resistance values must be positive") + else: + return (resistance_2 / resistance_1) * resistance_3 + + +if __name__ == "__main__": + import doctest + + doctest.testmod() +# print(wheatstone_solver(356,234,976)) From 11cdfae20104cc0f75b3a0d6e0c3a411774ec75f Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Fri, 6 Oct 2023 02:03:32 +0530 Subject: [PATCH 02/17] Update wheatstone_bridge.py --- electronics/wheatstone_bridge.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/electronics/wheatstone_bridge.py b/electronics/wheatstone_bridge.py index 02aa9f6e05f1..a618855ae747 100644 --- a/electronics/wheatstone_bridge.py +++ b/electronics/wheatstone_bridge.py @@ -4,7 +4,7 @@ def wheatstone_solver( resistance_1: float, resistance_2: float, resistance_3: float -) -> tuple: +) -> float: """ This function can calculate the unknown resistance in an wheatstone network. @@ -26,11 +26,10 @@ def wheatstone_solver( if resistance_1 <= 0 or resistance_2 <= 0 or resistance_3 <= 0: raise ValueError("All resistance values must be positive") else: - return (resistance_2 / resistance_1) * resistance_3 + return float((resistance_2 / resistance_1) * resistance_3) if __name__ == "__main__": import doctest doctest.testmod() -# print(wheatstone_solver(356,234,976)) From dd1587ae8337392e05bf2a6d523d1c1698ae7d32 Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Fri, 6 Oct 2023 02:10:54 +0530 Subject: [PATCH 03/17] Update wheatstone_bridge.py --- electronics/wheatstone_bridge.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/electronics/wheatstone_bridge.py b/electronics/wheatstone_bridge.py index a618855ae747..3529a09339c4 100644 --- a/electronics/wheatstone_bridge.py +++ b/electronics/wheatstone_bridge.py @@ -6,7 +6,13 @@ def wheatstone_solver( resistance_1: float, resistance_2: float, resistance_3: float ) -> float: """ - This function can calculate the unknown resistance in an wheatstone network. + This function can calculate the unknown resistance in an wheatstone network, + given that the three other resistances in the network are known. + The formula to calculate the same is: + + --------------- + |Rx=(R2/R1)*R3| + --------------- Usage examples: >>> wheatstone_solver(resistance_1=2, resistance_2=4, resistance_3=5) From 3e71b88f5a9935877875f067cfa39ffe60a442eb Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Sat, 14 Oct 2023 22:34:23 +0530 Subject: [PATCH 04/17] Create IC_555_Timer.py --- electronics/IC_555_Timer.py | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 electronics/IC_555_Timer.py diff --git a/electronics/IC_555_Timer.py b/electronics/IC_555_Timer.py new file mode 100644 index 000000000000..00df844276cd --- /dev/null +++ b/electronics/IC_555_Timer.py @@ -0,0 +1,50 @@ +# https://en.wikipedia.org/wiki/555_timer_IC#Astable +from __future__ import annotations + + +def astable_mode( + resistance_1: float, resistance_2: float, capacitance: float +) -> dist[str:float]: + """ + This function can calculate the frequency and duty cycle of an astable 555 timer. + The function takes in the value of the external resistances (in OHMS) and + capacitance (in microFARADS), and calculates the following: + + ------------------------------------- + | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz + ------------------------------------- + + ------------------------------------------------ + | Duty Cycle = (R1 + R2) / (R1 + 2 x R2) x 100 | ... in % + ------------------------------------------------ + + Usage examples: + >>>astable_mode(resistance_1=45, resistance_2=45, capacitance=7) + {'Frequency': 1523.8095238095239, 'Duty_Cycle': 66.66666666666666} + >>>astable_mode(resistance_1=356, resistance_2=234, capacitance=976) + {'Frequency': 1.7905459175553078, 'Duty_Cycle': 71.60194174757282} + >>>astable_mode(resistance_1=2, resistance_2=-1, capacitance=2) + Traceback (most recent call last): + ... + ValueError: All values must be positive + >>>astable_mode(resistance_1=0, resistance_2=0, capacitance=2) + Traceback (most recent call last): + ... + ValueError: All values must be positive + """ + + if resistance_1 <= 0 or resistance_2 <= 0 or capacitance <= 0: + raise ValueError("All values must be positive") + else: + frequency = (1.44 / ((resistance_1 + 2 * resistance_2) * capacitance)) * 10**6 + + duty_cycle = ( + (resistance_1 + resistance_2) / (resistance_1 + 2 * resistance_2) * 100 + ) + return {"Frequency": frequency, "Duty_Cycle": duty_cycle} + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From 1925e2a9d9c31074fc70b8895ca2187cd41a9e92 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Oct 2023 17:07:03 +0000 Subject: [PATCH 05/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- electronics/IC_555_Timer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/electronics/IC_555_Timer.py b/electronics/IC_555_Timer.py index 00df844276cd..94cacd438501 100644 --- a/electronics/IC_555_Timer.py +++ b/electronics/IC_555_Timer.py @@ -7,9 +7,9 @@ def astable_mode( ) -> dist[str:float]: """ This function can calculate the frequency and duty cycle of an astable 555 timer. - The function takes in the value of the external resistances (in OHMS) and + The function takes in the value of the external resistances (in OHMS) and capacitance (in microFARADS), and calculates the following: - + ------------------------------------- | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz ------------------------------------- From d5ba10577b78af70ac16347d35a65977351d96bc Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:05:30 +0530 Subject: [PATCH 06/17] Update IC_555_Timer.py --- electronics/IC_555_Timer.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/electronics/IC_555_Timer.py b/electronics/IC_555_Timer.py index 94cacd438501..381f2d2745ea 100644 --- a/electronics/IC_555_Timer.py +++ b/electronics/IC_555_Timer.py @@ -1,33 +1,42 @@ # https://en.wikipedia.org/wiki/555_timer_IC#Astable from __future__ import annotations - -def astable_mode( - resistance_1: float, resistance_2: float, capacitance: float -) -> dist[str:float]: - """ - This function can calculate the frequency and duty cycle of an astable 555 timer. - The function takes in the value of the external resistances (in OHMS) and +""" + This function can calculate the frequency and duty cycle of an astable 555 timer + The function takes in the value of the external resistances (in OHMS) and capacitance (in microFARADS), and calculates the following: - + ------------------------------------- | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz ------------------------------------- + where Freq is the frequency, + R1 is the first resisitance, + R2 is the second resistance, + C1 is the capacitance ------------------------------------------------ | Duty Cycle = (R1 + R2) / (R1 + 2 x R2) x 100 | ... in % ------------------------------------------------ + where R1 is the first resisitance, + R2 is the second resistance, + +""" + +def astable_mode( + resistance_1: float, resistance_2: float, capacitance: float +) -> dist[str:float]: + """ Usage examples: - >>>astable_mode(resistance_1=45, resistance_2=45, capacitance=7) + >>> astable_mode(resistance_1=45, resistance_2=45, capacitance=7) {'Frequency': 1523.8095238095239, 'Duty_Cycle': 66.66666666666666} - >>>astable_mode(resistance_1=356, resistance_2=234, capacitance=976) + >>> astable_mode(resistance_1=356, resistance_2=234, capacitance=976) {'Frequency': 1.7905459175553078, 'Duty_Cycle': 71.60194174757282} - >>>astable_mode(resistance_1=2, resistance_2=-1, capacitance=2) + >>> astable_mode(resistance_1=2, resistance_2=-1, capacitance=2) Traceback (most recent call last): ... ValueError: All values must be positive - >>>astable_mode(resistance_1=0, resistance_2=0, capacitance=2) + >>> astable_mode(resistance_1=0, resistance_2=0, capacitance=2) Traceback (most recent call last): ... ValueError: All values must be positive From 04594a26668b3fccff4da8ad62cea802db60f0bb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Oct 2023 17:36:23 +0000 Subject: [PATCH 07/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- electronics/IC_555_Timer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/electronics/IC_555_Timer.py b/electronics/IC_555_Timer.py index 381f2d2745ea..227fbae5be2f 100644 --- a/electronics/IC_555_Timer.py +++ b/electronics/IC_555_Timer.py @@ -3,9 +3,9 @@ """ This function can calculate the frequency and duty cycle of an astable 555 timer - The function takes in the value of the external resistances (in OHMS) and + The function takes in the value of the external resistances (in OHMS) and capacitance (in microFARADS), and calculates the following: - + ------------------------------------- | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz ------------------------------------- @@ -19,7 +19,7 @@ ------------------------------------------------ where R1 is the first resisitance, R2 is the second resistance, - + """ From 2fcd19737303ab30ff72534fb0378b4599182d35 Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:08:14 +0530 Subject: [PATCH 08/17] Update IC_555_Timer.py --- electronics/IC_555_Timer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electronics/IC_555_Timer.py b/electronics/IC_555_Timer.py index 227fbae5be2f..e17bd1faa8f9 100644 --- a/electronics/IC_555_Timer.py +++ b/electronics/IC_555_Timer.py @@ -25,7 +25,7 @@ def astable_mode( resistance_1: float, resistance_2: float, capacitance: float -) -> dist[str:float]: +) -> dict[str:float]: """ Usage examples: >>> astable_mode(resistance_1=45, resistance_2=45, capacitance=7) From 7c3977978dc4ea5ee7e3e6e635ddf98e2ba008ea Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:13:03 +0530 Subject: [PATCH 09/17] Update and rename IC_555_Timer.py to ic_555_timer.py --- electronics/IC_555_Timer.py | 59 ------------------ electronics/ic_555_timer.py | 118 ++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 59 deletions(-) delete mode 100644 electronics/IC_555_Timer.py create mode 100644 electronics/ic_555_timer.py diff --git a/electronics/IC_555_Timer.py b/electronics/IC_555_Timer.py deleted file mode 100644 index e17bd1faa8f9..000000000000 --- a/electronics/IC_555_Timer.py +++ /dev/null @@ -1,59 +0,0 @@ -# https://en.wikipedia.org/wiki/555_timer_IC#Astable -from __future__ import annotations - -""" - This function can calculate the frequency and duty cycle of an astable 555 timer - The function takes in the value of the external resistances (in OHMS) and - capacitance (in microFARADS), and calculates the following: - - ------------------------------------- - | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz - ------------------------------------- - where Freq is the frequency, - R1 is the first resisitance, - R2 is the second resistance, - C1 is the capacitance - - ------------------------------------------------ - | Duty Cycle = (R1 + R2) / (R1 + 2 x R2) x 100 | ... in % - ------------------------------------------------ - where R1 is the first resisitance, - R2 is the second resistance, - -""" - - -def astable_mode( - resistance_1: float, resistance_2: float, capacitance: float -) -> dict[str:float]: - """ - Usage examples: - >>> astable_mode(resistance_1=45, resistance_2=45, capacitance=7) - {'Frequency': 1523.8095238095239, 'Duty_Cycle': 66.66666666666666} - >>> astable_mode(resistance_1=356, resistance_2=234, capacitance=976) - {'Frequency': 1.7905459175553078, 'Duty_Cycle': 71.60194174757282} - >>> astable_mode(resistance_1=2, resistance_2=-1, capacitance=2) - Traceback (most recent call last): - ... - ValueError: All values must be positive - >>> astable_mode(resistance_1=0, resistance_2=0, capacitance=2) - Traceback (most recent call last): - ... - ValueError: All values must be positive - """ - - if resistance_1 <= 0 or resistance_2 <= 0 or capacitance <= 0: - raise ValueError("All values must be positive") - else: - frequency = (1.44 / ((resistance_1 + 2 * resistance_2) * capacitance)) * 10**6 - - duty_cycle = ( - (resistance_1 + resistance_2) / (resistance_1 + 2 * resistance_2) * 100 - ) - return {"Frequency": frequency, "Duty_Cycle": duty_cycle} - - -if __name__ == "__main__": - import doctest - - doctest.testmod() diff --git a/electronics/ic_555_timer.py b/electronics/ic_555_timer.py new file mode 100644 index 000000000000..19d589cf4d63 --- /dev/null +++ b/electronics/ic_555_timer.py @@ -0,0 +1,118 @@ +# https://en.wikipedia.org/wiki/555_timer_IC#Astable +from __future__ import annotations + +""" + This function can calculate the frequency and duty cycle of an astable 555 timer + The function takes in the value of the external resistances (in OHMS) and + capacitance (in microFARADS), and calculates the following: + + ------------------------------------- + | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz + ------------------------------------- + where Freq is the frequency, + R1 is the first resisitance, + R2 is the second resistance, + C1 is the capacitance + + ------------------------------------------------ + | Duty Cycle = (R1 + R2) / (R1 + 2 x R2) x 100 | ... in % + ------------------------------------------------ + where R1 is the first resisitance, + R2 is the second resistance, + +""" + + +def astable_mode( + resistance_1: float, resistance_2: float, capacitance: float +) -> # https://en.wikipedia.org/wiki/555_timer_IC#Astable +from __future__ import annotations + +""" + This function can calculate the frequency and duty cycle of an astable 555 timer + The function takes in the value of the external resistances (in OHMS) and + capacitance (in microFARADS), and calculates the following: + + ------------------------------------- + | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz + ------------------------------------- + where Freq is the frequency, + R1 is the first resisitance, + R2 is the second resistance, + C1 is the capacitance + + ------------------------------------------------ + | Duty Cycle = (R1 + R2) / (R1 + 2 x R2) x 100 | ... in % + ------------------------------------------------ + where R1 is the first resisitance, + R2 is the second resistance, + +""" + + +def astable_mode( + resistance_1: float, resistance_2: float, capacitance: float +) -> dict[str:float,str:float]: + """ + Usage examples: + >>> astable_mode(resistance_1=45, resistance_2=45, capacitance=7) + {'Frequency': 1523.8095238095239, 'Duty_Cycle': 66.66666666666666} + >>> astable_mode(resistance_1=356, resistance_2=234, capacitance=976) + {'Frequency': 1.7905459175553078, 'Duty_Cycle': 71.60194174757282} + >>> astable_mode(resistance_1=2, resistance_2=-1, capacitance=2) + Traceback (most recent call last): + ... + ValueError: All values must be positive + >>> astable_mode(resistance_1=0, resistance_2=0, capacitance=2) + Traceback (most recent call last): + ... + ValueError: All values must be positive + """ + + if resistance_1 <= 0 or resistance_2 <= 0 or capacitance <= 0: + raise ValueError("All values must be positive") + else: + frequency = (1.44 / ((resistance_1 + 2 * resistance_2) * capacitance)) * 10**6 + + duty_cycle = ( + (resistance_1 + resistance_2) / (resistance_1 + 2 * resistance_2) * 100 + ) + return {"Frequency": frequency, "Duty_Cycle": duty_cycle} + + +if __name__ == "__main__": + import doctest + + doctest.testmod() +: + """ + Usage examples: + >>> astable_mode(resistance_1=45, resistance_2=45, capacitance=7) + {'Frequency': 1523.8095238095239, 'Duty_Cycle': 66.66666666666666} + >>> astable_mode(resistance_1=356, resistance_2=234, capacitance=976) + {'Frequency': 1.7905459175553078, 'Duty_Cycle': 71.60194174757282} + >>> astable_mode(resistance_1=2, resistance_2=-1, capacitance=2) + Traceback (most recent call last): + ... + ValueError: All values must be positive + >>> astable_mode(resistance_1=0, resistance_2=0, capacitance=2) + Traceback (most recent call last): + ... + ValueError: All values must be positive + """ + + if resistance_1 <= 0 or resistance_2 <= 0 or capacitance <= 0: + raise ValueError("All values must be positive") + else: + frequency = (1.44 / ((resistance_1 + 2 * resistance_2) * capacitance)) * 10**6 + + duty_cycle = ( + (resistance_1 + resistance_2) / (resistance_1 + 2 * resistance_2) * 100 + ) + return {"Frequency": frequency, "Duty_Cycle": duty_cycle} + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From 0c05a6c58f22a72cf92bb8622510ece1a1895bf9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Oct 2023 17:43:36 +0000 Subject: [PATCH 10/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- electronics/ic_555_timer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/electronics/ic_555_timer.py b/electronics/ic_555_timer.py index 19d589cf4d63..a4675531c44c 100644 --- a/electronics/ic_555_timer.py +++ b/electronics/ic_555_timer.py @@ -30,9 +30,9 @@ def astable_mode( """ This function can calculate the frequency and duty cycle of an astable 555 timer - The function takes in the value of the external resistances (in OHMS) and + The function takes in the value of the external resistances (in OHMS) and capacitance (in microFARADS), and calculates the following: - + ------------------------------------- | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz ------------------------------------- @@ -46,7 +46,7 @@ def astable_mode( ------------------------------------------------ where R1 is the first resisitance, R2 is the second resistance, - + """ From c67af7cfa1dd11598cbec7ce4b1c0d40561fa0d4 Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:16:13 +0530 Subject: [PATCH 11/17] Update ic_555_timer.py --- electronics/ic_555_timer.py | 65 ++----------------------------------- 1 file changed, 3 insertions(+), 62 deletions(-) diff --git a/electronics/ic_555_timer.py b/electronics/ic_555_timer.py index a4675531c44c..6573c285983f 100644 --- a/electronics/ic_555_timer.py +++ b/electronics/ic_555_timer.py @@ -3,9 +3,9 @@ """ This function can calculate the frequency and duty cycle of an astable 555 timer - The function takes in the value of the external resistances (in OHMS) and + The function takes in the value of the external resistances (in OHMS) and capacitance (in microFARADS), and calculates the following: - + ------------------------------------- | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz ------------------------------------- @@ -19,34 +19,7 @@ ------------------------------------------------ where R1 is the first resisitance, R2 is the second resistance, - -""" - - -def astable_mode( - resistance_1: float, resistance_2: float, capacitance: float -) -> # https://en.wikipedia.org/wiki/555_timer_IC#Astable -from __future__ import annotations - -""" - This function can calculate the frequency and duty cycle of an astable 555 timer - The function takes in the value of the external resistances (in OHMS) and - capacitance (in microFARADS), and calculates the following: - - ------------------------------------- - | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz - ------------------------------------- - where Freq is the frequency, - R1 is the first resisitance, - R2 is the second resistance, - C1 is the capacitance - - ------------------------------------------------ - | Duty Cycle = (R1 + R2) / (R1 + 2 x R2) x 100 | ... in % - ------------------------------------------------ - where R1 is the first resisitance, - R2 is the second resistance, - + """ @@ -80,38 +53,6 @@ def astable_mode( return {"Frequency": frequency, "Duty_Cycle": duty_cycle} -if __name__ == "__main__": - import doctest - - doctest.testmod() -: - """ - Usage examples: - >>> astable_mode(resistance_1=45, resistance_2=45, capacitance=7) - {'Frequency': 1523.8095238095239, 'Duty_Cycle': 66.66666666666666} - >>> astable_mode(resistance_1=356, resistance_2=234, capacitance=976) - {'Frequency': 1.7905459175553078, 'Duty_Cycle': 71.60194174757282} - >>> astable_mode(resistance_1=2, resistance_2=-1, capacitance=2) - Traceback (most recent call last): - ... - ValueError: All values must be positive - >>> astable_mode(resistance_1=0, resistance_2=0, capacitance=2) - Traceback (most recent call last): - ... - ValueError: All values must be positive - """ - - if resistance_1 <= 0 or resistance_2 <= 0 or capacitance <= 0: - raise ValueError("All values must be positive") - else: - frequency = (1.44 / ((resistance_1 + 2 * resistance_2) * capacitance)) * 10**6 - - duty_cycle = ( - (resistance_1 + resistance_2) / (resistance_1 + 2 * resistance_2) * 100 - ) - return {"Frequency": frequency, "Duty_Cycle": duty_cycle} - - if __name__ == "__main__": import doctest From f6cce1b265b9432643f956fcdcaeac8f60c15f09 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Oct 2023 17:46:46 +0000 Subject: [PATCH 12/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- electronics/ic_555_timer.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/electronics/ic_555_timer.py b/electronics/ic_555_timer.py index 6573c285983f..8c23e666b03a 100644 --- a/electronics/ic_555_timer.py +++ b/electronics/ic_555_timer.py @@ -3,9 +3,9 @@ """ This function can calculate the frequency and duty cycle of an astable 555 timer - The function takes in the value of the external resistances (in OHMS) and + The function takes in the value of the external resistances (in OHMS) and capacitance (in microFARADS), and calculates the following: - + ------------------------------------- | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz ------------------------------------- @@ -19,13 +19,13 @@ ------------------------------------------------ where R1 is the first resisitance, R2 is the second resistance, - + """ def astable_mode( resistance_1: float, resistance_2: float, capacitance: float -) -> dict[str:float,str:float]: +) -> dict[str:float, str:float]: """ Usage examples: >>> astable_mode(resistance_1=45, resistance_2=45, capacitance=7) From 6db088837548058fb2ad39d3e7e5b290cf40232e Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:25:38 +0530 Subject: [PATCH 13/17] Update ic_555_timer.py --- electronics/ic_555_timer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electronics/ic_555_timer.py b/electronics/ic_555_timer.py index 8c23e666b03a..6ae20580753d 100644 --- a/electronics/ic_555_timer.py +++ b/electronics/ic_555_timer.py @@ -25,7 +25,7 @@ def astable_mode( resistance_1: float, resistance_2: float, capacitance: float -) -> dict[str:float, str:float]: +) -> dict[str: float, str: float]: """ Usage examples: >>> astable_mode(resistance_1=45, resistance_2=45, capacitance=7) From 24931e2bb50e2841e0460cec21b7f84d21b65261 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 14 Oct 2023 17:56:11 +0000 Subject: [PATCH 14/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- electronics/ic_555_timer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/electronics/ic_555_timer.py b/electronics/ic_555_timer.py index 6ae20580753d..8c23e666b03a 100644 --- a/electronics/ic_555_timer.py +++ b/electronics/ic_555_timer.py @@ -25,7 +25,7 @@ def astable_mode( resistance_1: float, resistance_2: float, capacitance: float -) -> dict[str: float, str: float]: +) -> dict[str:float, str:float]: """ Usage examples: >>> astable_mode(resistance_1=45, resistance_2=45, capacitance=7) From 95f2fb1f5f3e18c5e5aec3ae7541b178894bef6f Mon Sep 17 00:00:00 2001 From: Aroson <74296409+Aroson1@users.noreply.github.com> Date: Sun, 15 Oct 2023 16:13:15 +0530 Subject: [PATCH 15/17] Update ic_555_timer.py --- electronics/ic_555_timer.py | 46 +++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/electronics/ic_555_timer.py b/electronics/ic_555_timer.py index 8c23e666b03a..9fa0047fd5df 100644 --- a/electronics/ic_555_timer.py +++ b/electronics/ic_555_timer.py @@ -3,9 +3,9 @@ """ This function can calculate the frequency and duty cycle of an astable 555 timer - The function takes in the value of the external resistances (in OHMS) and + The function takes in the value of the external resistances (in OHMS) and capacitance (in microFARADS), and calculates the following: - + ------------------------------------- | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz ------------------------------------- @@ -19,24 +19,24 @@ ------------------------------------------------ where R1 is the first resisitance, R2 is the second resistance, - + """ -def astable_mode( +def astable_frequency( resistance_1: float, resistance_2: float, capacitance: float -) -> dict[str:float, str:float]: +) -> float: """ Usage examples: - >>> astable_mode(resistance_1=45, resistance_2=45, capacitance=7) - {'Frequency': 1523.8095238095239, 'Duty_Cycle': 66.66666666666666} - >>> astable_mode(resistance_1=356, resistance_2=234, capacitance=976) - {'Frequency': 1.7905459175553078, 'Duty_Cycle': 71.60194174757282} - >>> astable_mode(resistance_1=2, resistance_2=-1, capacitance=2) + >>> astable_frequency(resistance_1=45, resistance_2=45, capacitance=7) + 1523.8095238095239 + >>> astable_frequency(resistance_1=356, resistance_2=234, capacitance=976) + 1.7905459175553078 + >>> astable_frequency(resistance_1=2, resistance_2=-1, capacitance=2) Traceback (most recent call last): ... ValueError: All values must be positive - >>> astable_mode(resistance_1=0, resistance_2=0, capacitance=2) + >>> astable_frequency(resistance_1=0, resistance_2=0, capacitance=2) Traceback (most recent call last): ... ValueError: All values must be positive @@ -46,11 +46,33 @@ def astable_mode( raise ValueError("All values must be positive") else: frequency = (1.44 / ((resistance_1 + 2 * resistance_2) * capacitance)) * 10**6 + return frequency + +def astable_duty_cycle(resistance_1: float, resistance_2: float) -> float: + """ + Usage examples: + >>> astable_duty_cycle(resistance_1=45, resistance_2=45) + 66.66666666666666 + >>> astable_duty_cycle(resistance_1=356, resistance_2=234) + 71.60194174757282 + >>> astable_duty_cycle(resistance_1=2, resistance_2=-1) + Traceback (most recent call last): + ... + ValueError: All values must be positive + >>> astable_duty_cycle(resistance_1=0, resistance_2=0) + Traceback (most recent call last): + ... + ValueError: All values must be positive + """ + + if resistance_1 <= 0 or resistance_2 <= 0: + raise ValueError("All values must be positive") + else: duty_cycle = ( (resistance_1 + resistance_2) / (resistance_1 + 2 * resistance_2) * 100 ) - return {"Frequency": frequency, "Duty_Cycle": duty_cycle} + return duty_cycle if __name__ == "__main__": From 34baf642c37ecf659edee13b9340af4abf05728b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 15 Oct 2023 10:43:47 +0000 Subject: [PATCH 16/17] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- electronics/ic_555_timer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/electronics/ic_555_timer.py b/electronics/ic_555_timer.py index 9fa0047fd5df..3a3ab28b503f 100644 --- a/electronics/ic_555_timer.py +++ b/electronics/ic_555_timer.py @@ -3,9 +3,9 @@ """ This function can calculate the frequency and duty cycle of an astable 555 timer - The function takes in the value of the external resistances (in OHMS) and + The function takes in the value of the external resistances (in OHMS) and capacitance (in microFARADS), and calculates the following: - + ------------------------------------- | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz ------------------------------------- @@ -19,7 +19,7 @@ ------------------------------------------------ where R1 is the first resisitance, R2 is the second resistance, - + """ From 477a19be93464e9fa3276658fb37f94cc40395de Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 15 Oct 2023 17:32:01 +0200 Subject: [PATCH 17/17] Cleanup ic_555_timer.py --- electronics/ic_555_timer.py | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/electronics/ic_555_timer.py b/electronics/ic_555_timer.py index 3a3ab28b503f..e187e1928dca 100644 --- a/electronics/ic_555_timer.py +++ b/electronics/ic_555_timer.py @@ -1,25 +1,25 @@ -# https://en.wikipedia.org/wiki/555_timer_IC#Astable from __future__ import annotations """ - This function can calculate the frequency and duty cycle of an astable 555 timer - The function takes in the value of the external resistances (in OHMS) and - capacitance (in microFARADS), and calculates the following: + Calculate the frequency and/or duty cycle of an astable 555 timer. + * https://en.wikipedia.org/wiki/555_timer_IC#Astable + + These functions take in the value of the external resistances (in ohms) + and capacitance (in Microfarad), and calculates the following: ------------------------------------- | Freq = 1.44 /[( R1+ 2 x R2) x C1] | ... in Hz ------------------------------------- where Freq is the frequency, - R1 is the first resisitance, - R2 is the second resistance, - C1 is the capacitance + R1 is the first resistance in ohms, + R2 is the second resistance in ohms, + C1 is the capacitance in Microfarads. ------------------------------------------------ | Duty Cycle = (R1 + R2) / (R1 + 2 x R2) x 100 | ... in % ------------------------------------------------ - where R1 is the first resisitance, - R2 is the second resistance, - + where R1 is the first resistance in ohms, + R2 is the second resistance in ohms. """ @@ -36,7 +36,7 @@ def astable_frequency( Traceback (most recent call last): ... ValueError: All values must be positive - >>> astable_frequency(resistance_1=0, resistance_2=0, capacitance=2) + >>> astable_frequency(resistance_1=45, resistance_2=45, capacitance=0) Traceback (most recent call last): ... ValueError: All values must be positive @@ -44,9 +44,7 @@ def astable_frequency( if resistance_1 <= 0 or resistance_2 <= 0 or capacitance <= 0: raise ValueError("All values must be positive") - else: - frequency = (1.44 / ((resistance_1 + 2 * resistance_2) * capacitance)) * 10**6 - return frequency + return (1.44 / ((resistance_1 + 2 * resistance_2) * capacitance)) * 10**6 def astable_duty_cycle(resistance_1: float, resistance_2: float) -> float: @@ -68,11 +66,7 @@ def astable_duty_cycle(resistance_1: float, resistance_2: float) -> float: if resistance_1 <= 0 or resistance_2 <= 0: raise ValueError("All values must be positive") - else: - duty_cycle = ( - (resistance_1 + resistance_2) / (resistance_1 + 2 * resistance_2) * 100 - ) - return duty_cycle + return (resistance_1 + resistance_2) / (resistance_1 + 2 * resistance_2) * 100 if __name__ == "__main__":