#define POT_PIN A1
#define SENSE_PIN A7
#define START_PIN 0
#define MAIN_PIN A2
#define STAR_PIN A6
#define DELTA_PIN A4
const float ADC_REF = 5.0;
const float OVER_VOLTAGE = 2.0;
bool motorRunning = false;
bool starActive = false;
unsigned long starStartTime = 0;
unsigned long starDuration = 0;
void setup() {
pinMode(START_PIN, INPUT);
pinMode(MAIN_PIN, OUTPUT);
pinMode(STAR_PIN, OUTPUT);
pinMode(DELTA_PIN, OUTPUT);
stopAll();
}
void loop() {
float senseVoltage = analogRead(SENSE_PIN) * ADC_REF / 1023.0;
if (senseVoltage > OVER_VOLTAGE) {
stopAll();
motorRunning = false;
return;
}
bool startSignal = digitalRead(START_PIN);
if (startSignal && !motorRunning) {
motorRunning = true;
starActive = true;
int potValue = analogRead(POT_PIN);
starDuration = map(potValue, 0, 1023, 0, 120000UL);
starStartTime = millis();
digitalWrite(MAIN_PIN, HIGH);
digitalWrite(STAR_PIN, HIGH);
digitalWrite(DELTA_PIN, LOW);
}
if (motorRunning && starActive) {
if (millis() - starStartTime >= starDuration) {
// Turn off star, turn on delta
digitalWrite(STAR_PIN, LOW);
digitalWrite(DELTA_PIN, HIGH);
starActive = false;
}
}
if (!startSignal && motorRunning) {
stopAll();
motorRunning = false;
}
}
void stopAll() {
digitalWrite(MAIN_PIN, LOW);
digitalWrite(STAR_PIN, LOW);
digitalWrite(DELTA_PIN, LOW);
}
Comments