diff --git a/bluetoothControlApp.py b/bluetoothControlApp.py index 9df485041cc6efe7804533358e099a8ecf26a11e..3a3d04cab227f399b218deb5bd89bfeb4e3c6878 100644 --- a/bluetoothControlApp.py +++ b/bluetoothControlApp.py @@ -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() : diff --git a/distanceMeasure/button.py b/distanceMeasure/button.py index bbd0ec4c03c58add4e581cdd8e06ef61bfb06fad..611de0fbe4f65c3258e5842ea393815a973ef344 100644 --- a/distanceMeasure/button.py +++ b/distanceMeasure/button.py @@ -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!") diff --git a/distanceMeasure/modeSelector.py b/distanceMeasure/modeSelector.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/distanceMeasure/tfmini.py b/distanceMeasure/tfmini.py index b23fd1160dacf93582f47b9488fdbe534d8e37c6..34cb9687f833fc293f941756795427b15c509d19 100644 --- a/distanceMeasure/tfmini.py +++ b/distanceMeasure/tfmini.py @@ -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() diff --git a/piAndroidBluetooth/serialBluetooth.py b/piAndroidBluetooth/serialBluetooth.py index 935adf224825b5db6176a970b61b91c7baed12fa..b3cdefeac72b12f934997ac442d939109c953919 100644 --- a/piAndroidBluetooth/serialBluetooth.py +++ b/piAndroidBluetooth/serialBluetooth.py @@ -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()