from gpiozero import MCP3008, PWMLEDfrom time import sleep# 使用generator的用法,可自行測試# def convert_temp(gen):# for value in gen:# yield valuepwmled =PWMLED(27)adc_pr =MCP3008(0)adc_x =MCP3008(1)adc_y =MCP3008(2)try:whileTrue: data = adc_pr.value pwmled.value = dataprint('Light: {:.2f}'.format(data))print('X={:.2f}'.format(adc_x.value))print('Y={:.2f}'.format(adc_y.value))sleep(1)exceptKeyboardInterrupt:pass# 使用generator的用法,可自行測試# for temp in convert_temp(adc.values):# pwmled.value = temp# print('Light: {}'.format(temp))# sleep(1)