Initial commit
This commit is contained in:
21
Button.py
Normal file
21
Button.py
Normal file
@ -0,0 +1,21 @@
|
||||
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()
|
Reference in New Issue
Block a user