2 Python scripts use the same GPIO pin RPI
<p>Is it possible to write 2 scripts </p>

<p>1 For setting a GPIO pin</p>

<p>and 1 for reading out what the status of the gpio pin is.</p>

<p>I now have written these two scripts in python. but when I launch them both only 1 will work</p>

<pre><code>import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(18,GPIO.IN)
print GPIO.input(18)
</code></pre>

<p>The other one listens to a button and if the button is pressed the pin 18 is set to high, if he is pressed again the pin is set to low</p>

<pre><code>#!/usr/bin/python
import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)
pushbutton = 2
relay = 18

GPIO.setup(pushbutton, GPIO.IN)
GPIO.setup(relay, GPIO.OUT)

def main():
    ingedrukt = GPIO.input(pushbutton)
    try:
        while (True):
            if(ingedrukt == False):
                if(GPIO.input(pushbutton) == False):
                    sleep(0.5)
                    if(GPIO.input(pushbutton) ==False):
                        GPIO.output(relay, GPIO.HIGH)
                        ingedrukt = True
                        print "Pushed"
            else:
                if(GPIO.input(pushbutton) == True):
                    GPIO.output(relay, GPIO.LOW)
                    ingedrukt = False
                    print "Not pushed"
    except KeyboardInterrupt:
        print "Quit"
        GPIO.cleanup()
main()
</code></pre>

<p>Is this possible anyway if so, what am I doing wrong?</p>