Advertisement
aprsc7

main.py

Jun 23rd, 2021
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.55 KB | None | 0 0
  1. from adafruit_extended_bus import ExtendedI2C as I2C
  2. import adafruit_vl53l0x
  3. import BlynkLib
  4. #import tm1637
  5. import time
  6. import board
  7. import array as arr
  8.  
  9. # Constant and variable
  10. DIST_THRESHOLD = 1600
  11. Pathway = arr.array('i', [0, 0, 0, 0])
  12. PreviousPathway = 1
  13. count = 0
  14. i = 0
  15.  
  16. # initialize display
  17. #tm = tm1637.TM1637(clk=15, dio=14)
  18. #tm.number(count)
  19.  
  20. # initialize Blynk
  21. blynk = BlynkLib.Blynk('1uydc31qPohfeZzvCqASEktOBc0E9CRK')
  22.  
  23. # initialize sensor
  24. vl53_1 = adafruit_vl53l0x.VL53L0X(I2C(2))
  25. vl53_2 = adafruit_vl53l0x.VL53L0X(I2C(1))
  26.  
  27. while True:
  28.     blynk.run()
  29.  
  30.     # read sensor
  31.     sensor_1 = vl53_1.range
  32.     sensor_2 = vl53_2.range
  33.  
  34.     # send sensor range to cloud
  35.     #blynk.virtual_write(1, sensor_1)
  36.     #blynk.virtual_write(2, sensor_2)
  37.  
  38.     #print('i', i)
  39.  
  40.     # direction algorithm
  41.     if sensor_1 < DIST_THRESHOLD and sensor_2 < DIST_THRESHOLD:
  42.         Pathway[i] = 3
  43.         if Pathway[i] != Pathway[i-1]:
  44.             if i < 4:
  45.                 i += 1
  46.     elif sensor_2 < DIST_THRESHOLD:
  47.         Pathway[i] = 2
  48.         if Pathway[i] != Pathway[i-1]:
  49.             if i < 4:
  50.                 i += 1
  51.     elif sensor_1 < DIST_THRESHOLD:
  52.         Pathway[i] = 1
  53.         if Pathway[i] != Pathway[i-1]:
  54.             if i < 4:
  55.                 i += 1
  56.     else:
  57.         if i > 2:
  58.             if Pathway[0] == 1 and Pathway[1] == 3 and Pathway[2] == 2:
  59.                 count += 1
  60.                 #tm.number(count)
  61.                 if count < 1:
  62.                     blynk.virtual_write(1, 'not available')
  63.                     count = 0
  64.                 elif count == 1:
  65.                     blynk.virtual_write(1, 'available')
  66.                 else:
  67.                     blynk.virtual_write(1, 'with other student')
  68.                 blynk.virtual_write(3, count)
  69.                 #blynk.virtual_write(4, 'IN')
  70.                 Pathway = arr.array('i', [0, 0, 0, 0, 0])
  71.             elif Pathway[0] == 2 and Pathway[1] == 3 and Pathway[2] == 1:
  72.                 count -= 1
  73.                 #tm.number(count)
  74.                 if count < 1:
  75.                     blynk.virtual_write(1, 'not available')
  76.                     count = 0
  77.                 elif count == 1:
  78.                     blynk.virtual_write(1, 'available')
  79.                 else:
  80.                     blynk.virtual_write(1, 'with other student')
  81.                 blynk.virtual_write(3, count)
  82.                 #blynk.virtual_write(4, 'OUT')
  83.                 Pathway = arr.array('i', [0, 0, 0, 0, 0])
  84.         i = 0
  85.  
  86.     #print(Pathway[0], Pathway[1], Pathway[2])
  87.     #print('i', i)
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement