mirror of
https://github.com/Lapikud/arduino_remote.git
synced 2026-03-23 13:24:20 +00:00
Add my code
This commit is contained in:
35
Holger/ardu/ardu.py
Normal file
35
Holger/ardu/ardu.py
Normal file
@@ -0,0 +1,35 @@
|
||||
import serial.tools.list_ports
|
||||
import serial
|
||||
import time
|
||||
import threading
|
||||
|
||||
|
||||
last_input = time.time()
|
||||
dev = serial.tools.list_ports.comports()[0].device
|
||||
|
||||
ser = serial.Serial(dev)
|
||||
|
||||
|
||||
def read_input():
|
||||
while True:
|
||||
input2 = input("valgus: ")
|
||||
if input2 == "1":
|
||||
ser.write(b'A')
|
||||
else:
|
||||
ser.write(b'a')
|
||||
|
||||
global last_input
|
||||
last_input = time.time()
|
||||
|
||||
|
||||
the = threading.Thread(target=read_input)
|
||||
the.start()
|
||||
|
||||
while True:
|
||||
# print(time.time() - last_input)
|
||||
# time.sleep(1)
|
||||
if (time.time() - last_input) >= 3:
|
||||
ser.write(b'A')
|
||||
time.sleep(0.3)
|
||||
ser.write(b'a')
|
||||
time.sleep(0.5)
|
||||
46
Holger/ardu/templates/index.html
Normal file
46
Holger/ardu/templates/index.html
Normal file
@@ -0,0 +1,46 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<style>
|
||||
.button {
|
||||
/*background-color: red; !* Green *!*/
|
||||
border: none;
|
||||
color: white;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
font-size: 16px;
|
||||
margin: 4px 2px;
|
||||
cursor: pointer;
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.red {background-color: red;}
|
||||
|
||||
.blue {background-color: blue;}
|
||||
|
||||
.blink {background-color: black;}
|
||||
</style>
|
||||
<meta charset="UTF-8">
|
||||
<title>Tuli</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>tuli</h1>
|
||||
<a href="/red"><button class="button red">RED</button></a>
|
||||
|
||||
<br>
|
||||
<a href="/blue"><button class="button blue">BLUE</button></a>
|
||||
<br>
|
||||
<a href="/blink"><button class="button blink">BLINK</button></a>
|
||||
<br>
|
||||
|
||||
<form action="/led" method="post"><input type="submit" name="cmd" value="t">
|
||||
<input type="submit" name="cmd" value="q">
|
||||
<input type="submit" name="cmd" value="w"></form>
|
||||
<!--<a href="/toggle">TOGGLE</a>-->
|
||||
<!--{{olek}}-->
|
||||
<!--<form action="/toggle" method="post"><input type="submit" name="tuli" value="1"></form>-->
|
||||
<!--<form action="/on"><input type="submit" name="tuli" value="0"></form>-->
|
||||
</body>
|
||||
</html>
|
||||
81
Holger/ardu/web.py
Normal file
81
Holger/ardu/web.py
Normal file
@@ -0,0 +1,81 @@
|
||||
from flask import Flask, render_template, redirect, request
|
||||
import serial.tools.list_ports
|
||||
import serial
|
||||
import time
|
||||
import threading
|
||||
|
||||
|
||||
last_input = time.time()
|
||||
dev = serial.tools.list_ports.comports()[0].device
|
||||
|
||||
ser = serial.Serial(dev)
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
# def send(cmd):
|
||||
# ser = serial.Serial()
|
||||
# ser.rts = False
|
||||
# ser.dtr = False
|
||||
# ser.port = "COM9"
|
||||
# ser.open()
|
||||
# ser.write(cmd)
|
||||
# ser.close()
|
||||
|
||||
|
||||
@app.route('/led', methods=["POST"])
|
||||
def led():
|
||||
cmd = request.form.get("cmd")
|
||||
# send(cmd.encode())
|
||||
print(cmd)
|
||||
ser.write(cmd.encode())
|
||||
return redirect('/')
|
||||
|
||||
|
||||
@app.route('/')
|
||||
def hello_world():
|
||||
# ser.write(b" ")
|
||||
# olek = ser.readline()
|
||||
# ser.reset_input_buffer()
|
||||
olek = False
|
||||
return render_template("index.html", olek=olek)
|
||||
|
||||
|
||||
@app.route('/red')
|
||||
def on():
|
||||
ser.write(b"r")
|
||||
return redirect('/')
|
||||
|
||||
|
||||
@app.route('/blue')
|
||||
def off():
|
||||
ser.write(b"t")
|
||||
return redirect('/')
|
||||
|
||||
|
||||
@app.route('/blink')
|
||||
def blink():
|
||||
ser.write(b"l")
|
||||
return redirect('/')
|
||||
|
||||
|
||||
@app.route('/toggle', methods=["POST"])
|
||||
def toggle():
|
||||
request.form.get("tuli")
|
||||
ser.write(b" ")
|
||||
read = ser.readline().strip()
|
||||
print(read)
|
||||
if read == b'a':
|
||||
ser.write(b"r")
|
||||
else:
|
||||
ser.write(b"t")
|
||||
# if request.form.get("tuli") == "1":
|
||||
# on()
|
||||
# else:
|
||||
# off()
|
||||
return redirect('/')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run()
|
||||
|
||||
34
Holger/remote/remote.ino
Normal file
34
Holger/remote/remote.ino
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <IRLibAll.h>
|
||||
|
||||
IRsend mySender;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
char c = Serial.read();
|
||||
if (c != -1) {
|
||||
switch (c) {
|
||||
case 'm':
|
||||
mySender.send(NEC,0x0AA1, 12);
|
||||
break;
|
||||
case 'r':
|
||||
mySender.send(NEC,0xFF906F, 32);
|
||||
break;
|
||||
case 't':
|
||||
mySender.send(NEC,0xFF50AF, 32);
|
||||
break;
|
||||
case 'l':
|
||||
mySender.send(NEC,0xFFF00F, 32); // blink
|
||||
break;
|
||||
case 'q':
|
||||
mySender.send(NEC,0x4BB640B, 32); // vol +
|
||||
break;
|
||||
case 'w':
|
||||
mySender.send(NEC,0x4BB6C03F, 32); // vol -
|
||||
break;
|
||||
}
|
||||
Serial.write(c);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user