과제/라즈베리파이 피코
2023년 1학기 11주차 실습과제
Developer성현
2023. 5. 28. 00:05
11_2
import machine
import utime
adc = machine.ADC(0) # A0 핀에 연결된 ADC 생성
def read_light_intensity():
light_value = adc.read_u16() # ADC에서 아날로그 값 읽음
return light_value
while True:
light_intensity = read_light_intensity()
print("빛의 양:", light_intensity)
utime.sleep(1) # 1초간 대기 후 다시 측정
11_3
from machine import Pin, PWM
import time
adc = machine.ADC(0)
led = PWM(Pin(22))
led.freq(1000)
while True:
print("빛의 양:", adc.read_u16())
led.duty_u16(adc.read_u16())
time.sleep(0.1)
11_4
from machine import Pin
import time
from dht import DHT11, InvalidChecksum
sensor = DHT11(Pin(16, Pin.OUT, Pin.PULL_DOWN))
while True:
temp = sensor.temperature
humidity = sensor.humidity
print("온도: {}°C 습도: {:.0f}% ".format(temp, humidity))
time.sleep(2)
11_5
import machine
import utime
pir_pin = machine.Pin(28, machine.Pin.IN)
led_pin = machine.Pin(17, machine.Pin.OUT)
buzzer_pin = machine.Pin(16, machine.Pin.OUT)
def motion_detected():
led_pin.on() # LED 켜기
buzzer_pin.on() # 부저 울리기
utime.sleep(0.2) # 0.2초 동안 대기
led_pin.off() # LED 끄기
buzzer_pin.off() # 부저 멈추기
while True:
if pir_pin.value() == 1: # PIR 센서에서 움직임이 감지되면
motion_detected()
utime.sleep(0.1) # 0.1초간 대기 후 다시 확인
가지고 있는 센서가 불량이라 테스트가 불가능했습니다...