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 micro:bit Python Editor.
  • Set the project name to calculate_i_from_v_and_r, then click Save.
  • Click Send to 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

  • If the serial monitor isn't already open, click Show serial.
  • Try some of your own values, and use a calculator to verify the results are correct.