SHARE
TWEET

Untitled

a guest Oct 21st, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import wiringpi as wp
  2. import Queue
  3. import time
  4. import threading
  5.  
  6. wp.wiringPiSetup()
  7. AInput = 2
  8. BInput = 0
  9. CInput = 7
  10. DInput = 6
  11.  
  12. RState = 0
  13. LState = 0
  14.  
  15.  
  16.  
  17. def GetStepsRight():
  18.     global Rsteps
  19.     RlastState = 0
  20.     Rsteps = 0
  21.     wp.pullUpDnControl(AInput, 2)
  22.     wp.pullUpDnControl(BInput, 2)
  23.     while True:
  24.         AState = wp.digitalRead(AInput)
  25.         BState = wp.digitalRead(BInput) << 1
  26.         RState = AState | BState
  27.         if RlastState != RState:
  28.             if RState == 0:
  29.                 if RlastState == 2:
  30.                     Rsteps += 1
  31.                 elif RlastState == 3:
  32.                     Rsteps -= 1
  33.             elif RState == 2:
  34.                 if RlastState == 3:
  35.                     Rsteps += 1
  36.                 elif RlastState == 0:
  37.                     Rsteps -= 1
  38.             elif RState == 3:
  39.                 if RlastState == 0:
  40.                     Rsteps += 1
  41.                 elif RlastState == 2:
  42.                     Rsteps -= 1
  43.             RlastState = RState
  44.             #print(RState)
  45.         time.sleep(0.001)
  46.  
  47.  
  48. def GetStepsLeft():
  49.     global Lsteps
  50.     Lsteps = 0
  51.     LlastState =  0
  52.     wp.pullUpDnControl(CInput, 2)
  53.     wp.pullUpDnControl(DInput, 2)
  54.     while True:
  55.         CState = wp.digitalRead(CInput)
  56.         DState = wp.digitalRead(DInput) << 1
  57.         LState = CState | DState
  58.     #print(CState, DState)
  59.         if LlastState != LState:
  60.             if LState == 0:
  61.                 if LlastState == 2:
  62.                     Lsteps += 1
  63.                 elif LlastState == 3:
  64.                     Lsteps -= 1
  65.             elif LState == 2:
  66.                 if LlastState == 3:
  67.                     Lsteps += 1
  68.                 elif LlastState == 0:
  69.                     Lsteps -= 1
  70.             elif LState == 3:
  71.                 if LlastState == 0:
  72.                     Lsteps += 1
  73.                 elif LlastState == 2:
  74.                     Lsteps -= 1
  75.             LlastState = LState
  76.             #print(LState)
  77.             #out_queue.put(Lsteps)
  78.     time.sleep(0.001)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top