Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. import time
  3.  
  4. GPIO.setmode(GPIO.BCM)
  5. SCLPin=17
  6. SDOPin=4
  7.  
  8. HALF_BIT_TIME=.001
  9. CHARACTER_DELAY=5*HALF_BIT_TIME
  10.  
  11. NUM_BITS=16
  12.  
  13. GPIO.setup(SCLPin,GPIO.OUT)
  14. GPIO.setup(SDOPin,GPIO.IN)
  15.  
  16. GPIO.output(SCLPin,GPIO.HIGH)
  17. time.sleep(HALF_BIT_TIME)
  18. oldKey=18
  19.  
  20. try:
  21.         while True:
  22.                 button=1
  23.                 time.sleep(CHARACTER_DELAY)
  24.  
  25.                 while button < 17:
  26.                         print_button=button
  27.                         if (print_button==17):
  28.                                 print_button=1
  29.  
  30.                         GPIO.output(SCLPin,GPIO.LOW)
  31.                         time.sleep(HALF_BIT_TIME)
  32.                         keyval=GPIO.input(SDOPin)
  33.                         if not keyval:
  34.                                 pressed=True
  35.                                 if(oldKey!=button) :
  36.                                         print(print_button)
  37.                                         oldKey=button
  38.                         GPIO.output(SCLPin,GPIO.HIGH)
  39.                         time.sleep(HALF_BIT_TIME)
  40.  
  41.                         button+=1
  42.  
  43.                 pressed=False
  44. except KeyboardInterrupt:
  45.         pass
  46.         GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement