I was using these codes for passing variables from f1.py to f2.py, and it works perfectly:
f1.py:
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(23, GPIO.IN)
state = GPIO.input(23)
f2.py:
from f1 import state
print state
My problem now is that when I place f2.py inside an infinite loop, the variable state doesn't update. I even tried printing something inside f1.py to check if the "from f1 import state" part of the f2.py gets executed, but it is only executed once.
new f2.py:
while True:
from f1 import state
print state
How do I keep reading new values of "state" variable in f1 from f2?