Difference between revisions of "A button that does something"
Jump to navigation
Jump to search
Line 35: | Line 35: | ||
</source> | </source> | ||
− | [[Category:Raspberry | + | [[Category:Raspberry Pi]] |
Latest revision as of 11:14, 21 November 2022
So how about wiring a button input that is able to trigger an output?
We need something like this
and some code to run ( this example is just starting another code )
#!/usr/bin/env python
import RPi.GPIO as GPIO
import time
import os
import subprocess
GPIO.setmode(GPIO.BCM)
# setup pin 23 as an intput
GPIO.setup(23,GPIO.IN)
GPIO.add_event_detect(23, GPIO.RISING, bouncetime=800)
while True:
if GPIO.event_detected(23):
print 'click'
os.popen("python /root/Desktop/anothercode.py")
GPIO.cleanup()