def __init__(self): self.pcf8591 = Pcf8591(0x48) self.pca9685 = Pca9685() self.buzzer = ActiveBuzzer(35) self.dcmotor = DcMotor(self.pca9685) self.gas = Gas(self.pcf8591, ain=2) # 클래스 생성자에서 스레드 생성 self.hcsr = HcSr04(trigpin=40, echopin=38) # 클래스 생성자에서 스레드 생성 self.laser = Laser(37) self.photo = Photoresistor(self.pcf8591, 0) # 클래스 생성자에서 스레드 생성 self.led = RgbLed(redpin=16, greenpin=18, bluepin=22) self.servo1 = Sg90(self.pca9685, 0) # 카메라 서보1 self.servo2 = Sg90(self.pca9685, 1) # 카메라 서보2 self.servo3 = Sg90(self.pca9685, 8) # 초음파 서보 self.servo4 = Sg90(self.pca9685, 9) # 앞바퀴 서보 self.thermistor = Thermistor(self.pcf8591, 1) # 클래스 생성자에서 스레드 생성 self.tracker = Tracker(32) # 클래스 생성자에서 스레드 생성 self.lcd = Lcd1602(0x27)
def __init__(self, brokerIp, brokerPort, pubTopic): # 센서 값을 받아오기 위해 각각의 객체를 생성하고, Pin 번호도 동시에 설정 self.pca9685 = Pca9685() self.pcf8591 = Pcf8591(0x48) self.gas = Gas(self.pcf8591, ain=2) self.hcsr04 = HcSr04(trigpin=38, echopin=40) self.thermistor = Thermistor(self.pcf8591, 1) self.photoresister = Photoresister(self.pcf8591, ain=0) self.tracking = Tracking(Tracking=36) # SensorRover 객체 생성 시 받아온 값을 클래스 내에서 사용하기 위한 선언 self.brokerIp = brokerIp self.brokerPort = brokerPort self.pubTopic = pubTopic self.client = None # 속도 값을 받아 오기 위한 객체 생성 self.singletonSpeed = SingletonSpeed()
self.__lcd1602 = Lcd1602(0x27) def read(self): temp = self.__pcf8591.read(self.__ain) # 0 ~ 255 temp = 5 * float(temp) / 255 temp = 10000 * temp / (5 - temp) temp = 1 / (((math.log(temp / 10000)) / 3950) + (1 / (273.15 + 25))) tempSet = temp - 273.15 temperature = round(tempSet, 1) return temperature ################################################# if __name__ == '__main__': try: pcf8591 = Pcf8591(0x48) sensor = Thermistor(pcf8591, 1) lcd1602 = Lcd1602(0x27) while True: temperature = round(sensor.read(), 3) print('섭씨온도: {}도'.format(temperature)) time.sleep(1) lcd1602.write(0, 0, "Temperature") lcd1602.write(0, 1, str(temperature)) finally: lcd1602.write(0, 0, 'Program Exit') print('Program Exit')