Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from adafruit_extended_bus import ExtendedI2C as I2C
- import adafruit_vl53l0x
- import BlynkLib
- #import tm1637
- import time
- import board
- import array as arr
- # Constant and variable
- DIST_THRESHOLD = 1600
- Pathway = arr.array('i', [0, 0, 0, 0])
- PreviousPathway = 1
- count = 0
- i = 0
- # initialize display
- #tm = tm1637.TM1637(clk=15, dio=14)
- #tm.number(count)
- # initialize Blynk
- blynk = BlynkLib.Blynk('1uydc31qPohfeZzvCqASEktOBc0E9CRK')
- # initialize sensor
- vl53_1 = adafruit_vl53l0x.VL53L0X(I2C(2))
- vl53_2 = adafruit_vl53l0x.VL53L0X(I2C(1))
- while True:
- blynk.run()
- # read sensor
- sensor_1 = vl53_1.range
- sensor_2 = vl53_2.range
- # send sensor range to cloud
- #blynk.virtual_write(1, sensor_1)
- #blynk.virtual_write(2, sensor_2)
- #print('i', i)
- # direction algorithm
- if sensor_1 < DIST_THRESHOLD and sensor_2 < DIST_THRESHOLD:
- Pathway[i] = 3
- if Pathway[i] != Pathway[i-1]:
- if i < 4:
- i += 1
- elif sensor_2 < DIST_THRESHOLD:
- Pathway[i] = 2
- if Pathway[i] != Pathway[i-1]:
- if i < 4:
- i += 1
- elif sensor_1 < DIST_THRESHOLD:
- Pathway[i] = 1
- if Pathway[i] != Pathway[i-1]:
- if i < 4:
- i += 1
- else:
- if i > 2:
- if Pathway[0] == 1 and Pathway[1] == 3 and Pathway[2] == 2:
- count += 1
- #tm.number(count)
- if count < 1:
- blynk.virtual_write(1, 'not available')
- count = 0
- elif count == 1:
- blynk.virtual_write(1, 'available')
- else:
- blynk.virtual_write(1, 'with other student')
- blynk.virtual_write(3, count)
- #blynk.virtual_write(4, 'IN')
- Pathway = arr.array('i', [0, 0, 0, 0, 0])
- elif Pathway[0] == 2 and Pathway[1] == 3 and Pathway[2] == 1:
- count -= 1
- #tm.number(count)
- if count < 1:
- blynk.virtual_write(1, 'not available')
- count = 0
- elif count == 1:
- blynk.virtual_write(1, 'available')
- else:
- blynk.virtual_write(1, 'with other student')
- blynk.virtual_write(3, count)
- #blynk.virtual_write(4, 'OUT')
- Pathway = arr.array('i', [0, 0, 0, 0, 0])
- i = 0
- #print(Pathway[0], Pathway[1], Pathway[2])
- #print('i', i)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement