-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6749e2d
commit b353bc1
Showing
5 changed files
with
55 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"C_Cpp.default.compilerPath": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Idk man |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,29 @@ | ||
from flask import Flask, request, render_template | ||
from flask import Flask, render_template, jsonify | ||
import serial | ||
import time | ||
import threading | ||
|
||
app = Flask(__name__) | ||
arduino = serial.Serial('/dev/ttyACM0', 9600) | ||
arduino = serial.Serial('/dev/ttyACM0', 9600, timeout=1) | ||
arduino.flush() | ||
|
||
def send_to_arduino(speed): | ||
print(f"Sending to Arduino: {speed}") | ||
arduino.write(f"{speed}\n".encode()) | ||
data = {"counter": 0} | ||
|
||
def read_from_arduino(): | ||
while True: | ||
if arduino.in_waiting > 0: | ||
line = arduino.readline().decode('utf-8').rstrip() | ||
data["counter"] = line | ||
|
||
thread = threading.Thread(target=read_from_arduino) | ||
thread.start() | ||
|
||
@app.route('/') | ||
def index(): | ||
return render_template('index.html') | ||
return render_template('index.html', data=data) | ||
|
||
@app.route('/motor', methods=['POST']) | ||
def motor(): | ||
speed = request.form['speed'] | ||
print(f"Received speed: {speed}") | ||
send_to_arduino(speed) | ||
return f"Motor set to {speed}" | ||
@app.route('/data') | ||
def data(): | ||
return jsonify(data) | ||
|
||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0', port=8080) | ||
app.run(debug=True, host='0.0.0.0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
#include <Servo.h> | ||
|
||
Servo motor; | ||
|
||
void setup() { | ||
// Initialize serial communication at 9600 bits per second: | ||
Serial.begin(9600); | ||
motor.attach(9); // Attach the motor to pin 9 | ||
} | ||
|
||
void loop() { | ||
if (Serial.available() > 0) { | ||
int speed = Serial.parseInt(); // Read the speed value sent from the Raspberry Pi | ||
if (speed >= 0 && speed <= 180) { | ||
motor.write(speed); // Set the motor speed | ||
} | ||
} | ||
static int counter = 0; | ||
|
||
// Send the counter value | ||
Serial.println(counter); | ||
|
||
// Increment the counter | ||
counter++; | ||
|
||
// Wait for a second | ||
delay(1000); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters