title: Defining a variable, then changing its status throughout a program
body: <p>I am working on a project with raspberry pi for school. We were given a pi and told to create a project with it. I went with a NFC door lock. The problem is that I have very little (took online self-courses about 5yrs ago) experience with Python. I have taken a 100 level course for software development though. </p>
  
  <p>I have used a few example scripts to create a script for my nfc chip that mostly works. I just cannot quite figure out what I need in order to track the status of the door lock, and then reverse. So far my program will "lock" the door as the script starts, and continuously read for cards. (For the school project I am only lighting up LEDs instead of actually turning on a servo for the door.) I have one card programmed into the 'cardid' "database" and can successfully "unlock" the door with that card. The next step is to create a lockStatus that can be changed every time the good card is read. That way if the door is unlocked I can re-lock it.  </p>
  
  <p>So far what I have is:</p>
  
  <pre><code>def lockStatus(status):
      return lockStatus
  
  def doorStart():
      print "Locking the door to start:"
      gpio.output(lock, True)
      time.sleep(2.0)
      gpio.output(lock, False)
      lockStatus(True)
  
  def notAuth(status):
      gpio.output(lock, status)
      gpio.output(unlock, status)
  
  def checkCard():
      while 1:
  
      # Scan for cards    
          (status,TagType) = 
  MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
  
      # If a card is found
          if status == MIFAREReader.MI_OK:
              print "Card detected"
  
      # Get the UID of the card
          (status,uid) = MIFAREReader.MFRC522_Anticoll()
  
      # If we have the UID, continue
          if status == MIFAREReader.MI_OK:
  
              idnumber = uid[0], uid[1], uid[2], uid[3]
  
              #print idnumber
              db = shelve.open('cardid')
              idnumberdb = db['Card UID']
  
              if idnumber == idnumberdb:            
                  if  lockStatus(True):
                      gpio.output(unlock, True)
                      time.sleep(2.0)
                      gpio.output(unlock, False)
                      lockStatus(False)
                      print "Door Unlocked"
                  else:
                      gpio.output(lock, True)
                      time.sleep(2.0)
                      gpio.output(lock, False)
                      lockStatus(True)
                      print "Door Locked"
              else:
                  print "Card not authorized"
                  notAuth(True)
                  time.sleep(0.2)
                  notAuth(False)
                  time.sleep(0.2)
                  notAuth(True)
                  time.sleep(0.2)
                  notAuth(False)
                  time.sleep(0.2)
                  notAuth(True)
                  time.sleep(0.2)
                  notAuth(False)
  
          # Stop
          MIFAREReader.MFRC522_StopCrypto1()
  doorStart()
  checkCard()
  </code></pre>
  
  <p>I feel like I've already done a similar thing with the <code>notAuth</code> bit but when I have tried the same with by defining <code>lockStatus</code> I don't know how to set it up in my if statement. I imagine I want it to be something like.</p>
  
  <pre><code>if idnumber == idnumberdb
      if lockStatus(True):
          gpio.output(unlock, True)
          time.sleep(2.0)
          gpio.output(unlock, False)
          print "Door Unlocked"
          lockStatus(False)
      else:
          gpio.output(lock, True)
          time.sleep(2.0)
          gpio.output(lock, False)
          print "Door Locked"
          lockStatus(True)
  else:
      print "Card not authorized"
  </code></pre>
  
  <p>I'd appreciate any help. </p>
  
  <p>EDIT: I've changed the code, and added the function <code>lockStatus(status)</code></p>
  
  <p>It seems that my <code>if lockStatus(True):</code> isn't actually checking that "lockStatus == True" because it runs the unlock portion everytime.</p>
  
  <p>I've changed the <code>doorStart</code> to include an initial state <code>lockStatus(True)</code>
  and corrected the typo that was pointed out. 
  The modified complete code is now reflected above. </p>