From 71520eab9c30b4bc666d79b145a0d11d2501131e Mon Sep 17 00:00:00 2001 From: Edvin Date: Fri, 4 Apr 2025 11:21:49 +0200 Subject: Added control file --- control.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 control.py (limited to 'control.py') diff --git a/control.py b/control.py new file mode 100644 index 0000000..9c10693 --- /dev/null +++ b/control.py @@ -0,0 +1,49 @@ +import bluetooth +import time + +import termios +import tty +import sys + +def get_input() -> str: + + filedescriptors = termios.tcgetattr(sys.stdin) + tty.setcbreak(sys.stdin) + key = sys.stdin.read(1)[0] + termios.tcsetattr(sys.stdin, termios.TCSADRAIN,filedescriptors) + + return key + +pi = "B8:27:EB:D1:A5:A9" + +sock = bluetooth.BluetoothSocket(bluetooth.RFCOMM) +# sock.bind(("", bluetooth.PORT_ANY)) + +# port = sock.getsockname()[1] + +print("Attempting to connect to %s..." % pi) + +sock.connect((pi, 1)) + +print("Connected") + +input = "0" + +while input != "a": + input = get_input() + + if input == "i": + sock.send("11") + elif input == "j": + sock.send("44") + elif input == "l": + sock.send("33") + elif input == "k": + sock.send("22") + else: + sock.send("0") + print(input) + + time.sleep(0.1) + +sock.close() -- cgit v1.2.3