ottojo

Python Script

Jul 2nd, 2015
417
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2.  
  3. import os
  4. from time import sleep
  5. from espeak import espeak
  6. import random
  7. import RPi.GPIO as GPIO
  8.  
  9. GPIO.setmode(GPIO.BCM)
  10. GPIO.setup(23, GPIO.IN) #First Sensor Pin
  11. GPIO.setup(24, GPIO.IN) #Second Sensor Pin
  12.  
  13.  
  14. visitor_count = 0
  15. counter = 0
  16. in_first = False
  17. out_first = False
  18. limit = 10
  19.  
  20. responses = [   'you are visitor number []',
  21.                 'welcome, visitor []',
  22.                 'hi, visitor number[]',
  23.                 'take a look around, visitor number []']
  24. goodbye = [     'goodbye',
  25.                 'see you later']
  26.  
  27.  
  28.  
  29. def reset() :
  30.         global counter
  31.         global in_first
  32.         global out_first
  33.         counter = 0
  34.         in_first = False
  35.         out_first = False
  36.  
  37.  
  38. #espeak.set_voice("mb-us1")
  39. #espeak.set_parameter(espeak.Parameter.Rate, 200)
  40. while True:
  41.  
  42.         if GPIO.input(23) and GPIO.input(24):
  43.                 reset()
  44.                 continue
  45.         if debug:
  46.                 print "23: " + str(GPIO.input(23)) + ", 24: " + str(GPIO.input(24)) + " C: " + str(counter)
  47.  
  48.         if GPIO.input(23) and not(in_first):
  49.                 out_first = True
  50.  
  51.         if GPIO.input(24) and not(out_first):
  52.                 in_first = True
  53.  
  54.         if out_first or in_first :
  55.                 counter = counter + 1
  56.                 sleep(0.1)
  57.  
  58.         if out_first and GPIO.input(24) and (counter > 0) :
  59.  
  60.                 visitor_count = visitor_count + 1
  61.                 speak = random.choice(responses)  # Get a random response to speak back to the user
  62.                 espeak.synth(speak.replace("[]", str(visitor_count)))  # Speak back to the user!
  63.                 os.system('clear')
  64.                 print str(visitor_count)
  65.                 reset()
  66.  
  67.         if in_first and GPIO.input(23) and (counter > 0) :
  68.                 speak = random.choice(goodbye)  # Get a random response to speak back to the user
  69.                 espeak.synth(speak)  # Speak back to the user!
  70.                 reset()
  71.  
  72.         if counter > limit :
  73.                 reset()
RAW Paste Data