<-- back to the index of scripting examples
voltage divider calculator
Select two resistors that form a voltage divider and calculate output
voltage or tune resistor values when output voltage is changed. Can
modify resistor values on the drawing.
Example implementation
divider.fawk
Explanation, step by step
Select two resistors that form a voltage divider and calculate output voltage or tune resistor values when output voltage is changed.
The script picks up exactly two resistors from the selection and presents a dialog box where the user can change values. The calculator will recalculate the resulting value upon changes. If the user clicks on "set & close", the script writes back resulting resistor values.
Note: +0 in fawk (and in awk) triggers a conversion to numeric value. This is used to make sure arrays are indexed with numbers and numeric widgets are loaded with numbers.
How to test:
- load the script
- draw a voltage dicider using two resistor
- name the resistor, make sure their name start with R
- select the two resistor, but no other resistor (selecting wires and non-R symbols is okay)
- invoke the script from menu or with hotkey {p s d}
- change resistor values and input voltages to see output voltage recalculated
- change output voltage to see the non-locked resistor value recalculated
- click "set & close" to copy back the new resistor value(s) to the drawing