Page 40 - MDP2020-3
P. 40

34
                      |    인천전자마이스터고등학교  ·············································································································

                나.  온습도  측정을  하기  위한  프로그램  소스



            import  Adafruit_DHT


            import  time







            sensor  =  Adafruit_DHT.DHT11


            pin  =  4







            while  True:


                    humidity,  temperature  =  Adafruit_DHT.read_retry(sensor,  pin)







                    if  humidity  is  not  None  and  temperature  is  not  None:



                            print('Temp={0:0.1f}*C    Humidity={1:0.1f}%'.format(temperature,  humidity))


                            time.sleep(2)


                    else:



                            print('Failed  to  get  reading.  Try  again!')
   35   36   37   38   39   40   41   42   43   44   45