A button that does something

From Interaction Station Wiki
Jump to navigation Jump to search

So how about wiring a button input that is able to trigger an output?

We need something like this


Button breadboard.png


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()