Advertisement
KsaneK

Python -winda - maszyna stanowa - projekt

Dec 6th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.14 KB | None | 0 0
  1. import RPi.GPIO as GPIO
  2. from time import sleep
  3.  
  4. delay = 1
  5.  
  6. P1_PIN = 17
  7. P2_PIN = 27
  8. P3_PIN = 22
  9. S1_PIN = 23
  10. S2_PIN = 24
  11. S3_PIN = 25
  12. Q1_PIN = 7
  13. Q2_PIN = 8
  14.  
  15. S1 = S2 = S3 = P1 = P2 = P3 = 0
  16. M1 = M2 = M3 = M4 = 0
  17. M1p = M2p = M3p = M4p = 0
  18.  
  19. GPIO.setmode(GPIO.BCM)
  20. GPIO.setwarnings(False)
  21. GPIO.setup(P1_PIN, GPIO.IN)
  22. GPIO.setup(P2_PIN, GPIO.IN)
  23. GPIO.setup(P3_PIN, GPIO.IN)
  24. GPIO.setup(S1_PIN, GPIO.IN)
  25. GPIO.setup(S2_PIN, GPIO.IN)
  26. GPIO.setup(S3_PIN, GPIO.IN)
  27. GPIO.setup(Q1_PIN, GPIO.OUT)
  28. GPIO.setup(Q2_PIN, GPIO.OUT)
  29.  
  30. while(True):
  31.     P1 = GPIO.input(P1_PIN)
  32.     P2 = GPIO.input(P2_PIN)
  33.     P3 = GPIO.input(P3_PIN)
  34.     S1 = GPIO.input(S1_PIN)
  35.     S2 = GPIO.input(S2_PIN)
  36.     S3 = GPIO.input(S3_PIN)
  37.  
  38.     M1p = M1 and M2 and not M4 or M1 and not M3 and M4 and not S1 or \
  39.         not M1 and M2 and M3 and (M4 and S3 or not M4 and S2) or \
  40.         M1 and not M2 and ( not M3 and not M4 or M3 and M4 )
  41.     M2p = M1 and not M2 and M4 and (M3 and S3 or not M3 and S1) or \
  42.         M2 and M4 and (M1 and not M3 or not M1 and M3) or \
  43.         M2 and M3 and not M4 and not S2 or M2 and not M3 and not M4 or \
  44.         not M1 and not M2 and not M3 and not M4 and S1;
  45.     M3p = M1 and M2 and not M4 and (not M3 and P2 or M3 and not S2) or \
  46.         M3 and M4 and not S3 and (M1 and not M2 or not M1 and M2) or \
  47.         not M2 and not M3 and not M4 and (M1 and P3 or not M1 and S1) or \
  48.         not M1 and M2 and not M3 and not M4 and (P2 or P3) or \
  49.         not M1 and M2 and M3 and not M4 and not S2;
  50.     M4p = M1 and M2 and not M3 and (not M4 and P1 or M4 and not S1) or \
  51.         M1 and not M2 and M4 and (M3 and not S3 or not M3 and not S1) or \
  52.         not M1 and M2 and (M3 and M4 and not S3 or not M3 and not M4 and P3) or \
  53.         M1 and not M2 and not M3 and not M4 and (P1 or P3)
  54.     M1 = M1p;
  55.     M2 = M2p;
  56.     M3 = M3p;
  57.     M4 = M4p;
  58.     Q1 = not M1 and not M2 and not M3 and not M4 or \
  59.         M1 and M2 and M3 and not M4 or M1 and M2 and \
  60.         not M3 and M4 or M1 and not M2 and not M3 and M4;
  61.     Q2 = not M3 and not M4 and (M1 or M2);
  62.     GPIO.output(Q1_PIN, Q1)
  63.     GPIO.output(Q2_PIN, Q2)
  64.  
  65.     print("P: %d%d%d" % (P1, P2, P3))
  66.     print("S: %d%d%d" % (S1, S2, S3))
  67.     print("M: %d%d%d%d" % (M1, M2, M3, M4))
  68.     print("Q: %d%d" % (Q1, Q2))
  69.     print();
  70.  
  71.     sleep(delay)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement