Script and Tests

Current Calculator Example Script

Here is a micro:bit current calculator that you can run to check the current a resistor conducts based on its resistance value and the voltage measured at its leads.

  • Enter the calculate_i_from_v_and_r script into the python.microbit.org editor.
  • Update the Script Name field and then click Load/Save → Download Project Hex.
  • Click Connect and select the micro:bit and connect if a popup appears.
  • Click Flash to load the script into the micro:bit.
# calculate_i_from_v_and_r

from microbit import *

while True:
    text = input("Enter volts: ")
    V = float(text)
    text = input("Enter ohms: ")
    R = float(text)
    
    I = V / R
    
    print("I = ", I, "A")
    print()    

 

Test the Calculator

  • Click Open Serial, and then enter the values shown below.
  • Try some of your own values, and use a calculator to verify the results are correct.