Yes! you are right i want to execute in an one loop or you can say to utilize ESP32 with two more functions within one programming code loop , just one after another. This is just for to go one step further to play and practice with the learnt codes from a simple to a little bit more complex.davef wrote: ↑Mon Aug 02, 2021 9:29 amFirstly, sorry I see you do call sensor.temperature() and sensor.humidity()
It looks you have another file called main.py. Better post that as I don't understand:I understand that you want both of these to execute in the one loop, just one after another.Code: Select all
Ready to download this file,please wait! ... download ok exec(open('./main.py').read(),globals())
Sorry, but there is only one main.py file i have created and trying to execute two different programs within one main.py. The complete main.py code:
Code: Select all
from machine import Pin
from dht import DHT22
from time import sleep
led = Pin(2, Pin.OUT)
sensor = DHT22(Pin(14))
while True:
sensor.measure()
print('Temperature = %.2f' % sensor.temperature())
print('Humidity = %.2f' % sensor.humidity())
sleep(3)
led.on()
sleep(0.5)
led.off()
sleep(0.5)
>>>
Ready to download this file,please wait!
...
download ok
exec(open('./main.py').read(),globals())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 7, in <module>
NameError: name 'dht' isn't defined
>>>
>>>
>>>
Ready to download this file,please wait!
...
download ok
exec(open('./main.py').read(),globals())
Temperature = 25.60
Humidity = 87.90
Temperature = 25.90
Humidity = 87.60
Sensor code is working fine, but LED blinking code is not making to blink the LED as per its code. Thanks.