From 30614f0252f22a4db4f83843e8e917e05b5020c3 Mon Sep 17 00:00:00 2001 From: Hanna Keeman Date: Tue, 5 Nov 2019 21:41:10 +0200 Subject: [PATCH] Lisan oma koodi --- .gitignore | 1 + Hanna/arduino/main.py | 43 ++++++++++++++++++++++++++++++ Hanna/arduino/templates/index.html | 21 +++++++++++++++ Hanna/ir_test/ir_test.ino | 28 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 Hanna/arduino/main.py create mode 100644 Hanna/arduino/templates/index.html create mode 100644 Hanna/ir_test/ir_test.ino diff --git a/.gitignore b/.gitignore index 894a44c..70391ce 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,4 @@ venv.bak/ # mypy .mypy_cache/ +.idea/ \ No newline at end of file diff --git a/Hanna/arduino/main.py b/Hanna/arduino/main.py new file mode 100644 index 0000000..00b3778 --- /dev/null +++ b/Hanna/arduino/main.py @@ -0,0 +1,43 @@ +import serial +from flask import Flask, render_template, redirect, request + + +def send(cmd): + ser = serial.Serial() + ser.rts = False + ser.dtr = False + ser.port = "COM3" + ser.open() + ser.write(cmd) + ser.close() + + +app = Flask(__name__) + + +@app.route('/') +def hello_world(): + return render_template("index.html") + + +@app.route('/red') +def red(): + send(b"r") + return redirect('/') + + +@app.route('/blue') +def blue(): + send(b"t") + return redirect('/') + + +@app.route('/led', methods=["POST"]) +def led(): + cmd = request.form["cmd"] + send(cmd.encode()) + return redirect("/") + + +if __name__ == '__main__': + app.run(host="0.0.0.0") diff --git a/Hanna/arduino/templates/index.html b/Hanna/arduino/templates/index.html new file mode 100644 index 0000000..47fc3bc --- /dev/null +++ b/Hanna/arduino/templates/index.html @@ -0,0 +1,21 @@ + + + + + :D + + + +

+hi! +red +blue
+
+
+ + + +
+

+ + \ No newline at end of file diff --git a/Hanna/ir_test/ir_test.ino b/Hanna/ir_test/ir_test.ino new file mode 100644 index 0000000..c3065dd --- /dev/null +++ b/Hanna/ir_test/ir_test.ino @@ -0,0 +1,28 @@ +#include + +IRsend mySender; + +void setup() { + Serial.begin(9600); +} + +void loop() { + char c = Serial.read(); + if (c != -1) { + switch (c) { + case '+': + mySender.send(NEC,0x4BB640BF, 32); + break; + case '-': + mySender.send(NEC,0x4BB6C03F, 32); + break; + case 'r': + mySender.send(NEC,0xFF906F, 32); + break; + case 't': + mySender.send(NEC,0xFF50AF, 32); + break; + } + Serial.write(c); + } +}