Srxon05

Laser

May 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. #!/usr/local/bin/python
  2.  
  3. import RPi.GPIO as GPIO
  4. import time
  5. radi=False
  6.  
  7. GPIO.setmode(GPIO.BOARD)
  8. GPIO.setup(12,GPIO.OUT)
  9. GPIO.output(12,GPIO.LOW)
  10. pin_to_circuit = 7
  11. password=""
  12. i=0
  13. def rc_time (pin_to_circuit) :
  14.     count = 0
  15.    
  16.     GPIO.setup(pin_to_circuit, GPIO.OUT)
  17.     GPIO.output(pin_to_circuit, GPIO.LOW)
  18.     time.sleep(0.02)
  19.  
  20.     GPIO.setup(pin_to_circuit, GPIO.IN)
  21.  
  22.     while (GPIO.input(pin_to_circuit) == GPIO.LOW) :
  23.         count += 1
  24.  
  25.     return count
  26.  
  27.  
  28. try:
  29.     while True:
  30.  
  31.         if rc_time(pin_to_circuit)>100:
  32.             radi=True
  33.             while(radi):
  34.                 while(i<5):
  35.                     GPIO.output(12,GPIO.HIGH)
  36.                     time.sleep(0.25)
  37.                     GPIO.output(12,GPIO.LOW)
  38.                     time.sleep(0.5)
  39.                     i=i+1
  40.                 if(i==5):
  41.                     GPIO.output(12,GPIO.HIGH)
  42.                     i=0
  43.                 print"Unesite sifru: "
  44.                 password=str(raw_input())
  45.                 if(password=="pilab01"or password=="pilab02"):
  46.                     radi=False
  47.                     GPIO.output(12,GPIO.LOW)
  48.                 else:
  49.                     print "Pogresna lozinka!Ponovo unesite"
  50.                     i=0
  51.  
  52.         if(password=="pilab02"):
  53.             print"sistem je ugasen"
  54.             break                      
  55.         time.sleep(10)
  56. except KeyboardInterrupt:
  57.     pass
  58. finally:
  59.     GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment