calculate the frequency andor duty cycle of an astable 555 timer https en wikipedia orgwiki555timericastable 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 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 resistance in ohms r2 is the second resistance in ohms usage examples astablefrequencyresistance145 resistance245 capacitance7 1523 8095238095239 astablefrequencyresistance1356 resistance2234 capacitance976 1 7905459175553078 astablefrequencyresistance12 resistance21 capacitance2 traceback most recent call last valueerror all values must be positive astablefrequencyresistance145 resistance245 capacitance0 traceback most recent call last valueerror all values must be positive usage examples astabledutycycleresistance145 resistance245 66 66666666666666 astabledutycycleresistance1356 resistance2234 71 60194174757282 astabledutycycleresistance12 resistance21 traceback most recent call last valueerror all values must be positive astabledutycycleresistance10 resistance20 traceback most recent call last valueerror all values must be positive 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 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 resistance in ohms r2 is the second resistance in ohms usage examples 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_frequency resistance_1 45 resistance_2 45 capacitance 0 traceback most recent call last valueerror all values must be positive 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
from __future__ import annotations




def astable_frequency(
    resistance_1: float, resistance_2: float, capacitance: float
) -> float:
    

    if resistance_1 <= 0 or resistance_2 <= 0 or capacitance <= 0:
        raise ValueError("All values must be positive")
    return (1.44 / ((resistance_1 + 2 * resistance_2) * capacitance)) * 10**6


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")
    return (resistance_1 + resistance_2) / (resistance_1 + 2 * resistance_2) * 100


if __name__ == "__main__":
    import doctest

    doctest.testmod()