made pin 10 control a servo instead of the fan, still need to update the webpage to reflect that, and the stop makes it full and the full makes it stop atm

This commit is contained in:
Lucca Pirovano
2025-12-03 13:40:42 -05:00
parent 9646403938
commit d09a8e3364
@@ -1,48 +1,64 @@
// Dual Fan control via Serial works with the Python Flask UI // Dual control: Pin 11 = PWM fan, Pin 10 = TT motor (via IRF520 module)
// Pin 11 = Fan A (PWM) Pin 10 = Fan B (PWM) // Send via Serial: a0a9, af, as → fan | b0b9, bf, bs → TT motor
// Use transistor/MOSFET/driver for high-current fans! const int FAN_PIN = 11; // Regular PWM fan (can be directly on pin or via transistor)
const int MOTOR_PIN = 10; // TT motor → IRF520 SIG terminal
const int FAN_A_PIN = 11;
const int FAN_B_PIN = 10;
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
pinMode(FAN_A_PIN, OUTPUT); pinMode(FAN_PIN, OUTPUT);
pinMode(FAN_B_PIN, OUTPUT); pinMode(MOTOR_PIN, OUTPUT);
analogWrite(FAN_A_PIN, 0);
analogWrite(FAN_B_PIN, 0); // Start both stopped
Serial.println("Dual fan controller ready."); analogWrite(FAN_PIN, 0);
Serial.println("Format: <fan><cmd> (a/b)(0-9fs)"); analogWrite(MOTOR_PIN, 0);
Serial.println("Dual controller ready");
Serial.println("a0-a9/af/as = Fan | b0-b9/bf/bs = TT Motor");
} }
void loop() { void loop() {
if (Serial.available() < 2) return; // need fan + cmd if (Serial.available() < 2) return;
char fan = Serial.read(); char device = Serial.read(); // 'a'/'A' = fan, 'b'/'B' = motor
char cmd = Serial.read(); char cmd = Serial.read();
// ----- validate fan ----- // Select which pin we're controlling
const int *pin; int pin;
if (fan == 'a' || fan == 'A') pin = &FAN_A_PIN; char name;
else if (fan == 'b' || fan == 'B') pin = &FAN_B_PIN; if (device == 'a' || device == 'A') {
else { Serial.println("?"); return; } pin = FAN_PIN;
name = 'A';
}
else if (device == 'b' || device == 'B') {
pin = MOTOR_PIN;
name = 'B';
}
else {
Serial.println("?");
return;
}
// ----- compute speed ----- // Parse command
int speed = 0; int speed = 0;
cmd = tolower(cmd); cmd = tolower(cmd);
if (cmd >= '0' && cmd <= '9') { if (cmd >= '0' && cmd <= '9') {
speed = map(cmd - '0', 0, 9, 0, 255); // 0-9 → 0-255 speed = map(cmd - '0', 0, 9, 70, 255); // ← IMPORTANT for TT motor!
// 70 minimum → motor actually starts moving (adjust 6090 if needed)
}
else if (cmd == 'f') speed = 255; // full
else if (cmd == 's') speed = 0; // stop
else {
Serial.println("?");
return;
} }
else if (cmd == 'f') speed = 255;
else if (cmd == 's') speed = 0;
else { Serial.println("?"); return; }
// ----- apply ----- // Apply PWM
analogWrite(*pin, speed); analogWrite(pin, speed);
// ----- feedback (percent + which fan) ----- // Feedback
int percent = map(speed, 0, 255, 0, 100); int percent = map(speed, 0, 255, 0, 100);
Serial.print((fan == 'a' || fan == 'A') ? "A" : "B"); Serial.print(name);
Serial.print(percent); Serial.print(percent);
Serial.println("%"); Serial.println("%");
} }