Skip to content
Snippets Groups Projects
Commit 16cd77f6 authored by JeongMin Choi's avatar JeongMin Choi
Browse files

update

parent c7989441
No related branches found
No related tags found
No related merge requests found
......@@ -9,25 +9,29 @@ button0 = Button(11)
button1 = Button(13)
button2 = Button(15)
tf.open()
duration = 0.1
while True:
if os.path.exists("/dev/rfcomm0"):
blue = serialBluetooth()
while True:
try:
line = blue.read()
if(line != ""):
duration = float(line)
print(duration)
if button0.isPressed():
distance = tf.getDistance()
if blue.isOpen() :
blue.write("0,"+str(distance)+",0")
print("0,"+str(distance)+",0")
time.sleep(0.1)
time.sleep(duration)
elif button1.isPressed():
distance = tf.getDistance()
if blue.isOpen() :
blue.write("1,"+str(distance)+",0")
print("1,"+str(distance)+",0")
time.sleep(0.1)
time.sleep(duration)
elif button2.isPressed():
distance = tf.getDistance()
if blue.isOpen() :
......
......@@ -12,9 +12,13 @@ class Button:
return GPIO.input(self.pin)==GPIO.HIGH
if __name__ == '__main__':
button = Button(15)
count = 0
button1 = Button(11)
button2 = Button(13)
button3 = Button(15)
while True: # Run forever
if button.isPressed():
print("Button was pushed!", count)
count+=1
if button1.isPressed():
print("Button1 was pushed!")
if button2.isPressed():
print("Button2 was pushed!")
if button3.isPressed():
print("Button3 was pushed!")
......@@ -13,16 +13,17 @@ class TFmini:
self.ser.open()
def getDistance(self):
self.ser.reset_input_buffer()
while True:
count = self.ser.in_waiting
if count > 8:
recv = self.ser.read(9)
self.ser.reset_input_buffer()
if recv[0] == 'Y' and recv[1] == 'Y': # 0x59 == 89 is 'Y'
low = int(recv[2].encode('hex'), 16)
high = int(recv[3].encode('hex'), 16)
distance = low + high * 256
return distance
self.ser.reset_input_buffer()
def close(self):
if self.ser != None:
......@@ -39,5 +40,6 @@ if __name__ == '__main__':
while True:
if button.isPressed():
print(tfmini.getDistance())
time.sleep(0.1)
except KeyboardInterrupt: # Ctrl+C
tfmini.close()
......@@ -5,7 +5,7 @@ class serialBluetooth:
def __init__(self):
#see if i can do rfcomm watch hci0 here
#see if /dev/rfcomm0 exist
self.ser = serial.Serial('/dev/rfcomm0')
self.ser = serial.Serial('/dev/rfcomm0', timeout=0)
def isOpen(self):
return self.ser.isOpen()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment