22 lines
570 B
Python
22 lines
570 B
Python
import RPi.GPIO as GPIO
|
|
import time
|
|
|
|
# Konfigurasi GPIO
|
|
BUTTON_PIN = 22 # Pin GPIO yang digunakan
|
|
GPIO.setmode(GPIO.BCM)
|
|
GPIO.setup(BUTTON_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Pull-down resistor
|
|
|
|
print("Tekan tombol untuk menguji...")
|
|
|
|
try:
|
|
while True:
|
|
if GPIO.input(BUTTON_PIN) == GPIO.HIGH:
|
|
print("Tombol ditekan!")
|
|
else:
|
|
print("Tombol tidak ditekan.")
|
|
time.sleep(0.1) # Delay untuk menghindari pembacaan terlalu cepat
|
|
except KeyboardInterrupt:
|
|
print("Program dihentikan.")
|
|
finally:
|
|
GPIO.cleanup()
|