Files
raspi-iot-ryhmatyo/testaukset.py
2026-01-08 09:19:01 +00:00

29 lines
466 B
Python

import time
from grove.gpio import GPIO
import RPi.GPIO as rGPIO
led = GPIO(5, GPIO.OUT)
button = GPIO(6, GPIO.IN)
# create PWM instance
pwmPin = 12
rGPIO.setmode(rGPIO.BCM)
rGPIO.setup(pwmPin, rGPIO.OUT)
pwm = rGPIO.PWM(pwmPin, 10)
pwm.start(0)
# 1000 Hz sound
pwm.ChangeFrequency(1000)
while True:
if button.read():
led.write(1)
pwm.ChangeDutyCycle(100)
else:
led.write(0)
pwm.ChangeDutyCycle(0)
time.sleep(0.1)