Files
arduino/PontiacWiperOKakaDino5/PontiacWiperOKakaDino5.ino
2025-10-12 09:13:56 +02:00

129 lines
3.7 KiB
C++

// Pin Definitions
const int Sw0PotPin = A6;
const int Sw1OffParkPin = 2;
const int Sw1IntmPin = 3;
const int Sw1LoPin = 4;
const int Sw1HiPin = 5;
const int Rly1LoPin = 13;
const int Rly2HiPin = 14;
const int Rly3GndPin = 15;
const int Rly4WshPin = 16;
// Global Variables
int waitingTime = 5000; // Default waiting time in milliseconds (5 seconds)
bool isWipIntmRunning = false; // Flag to track if WipIntm function is running
unsigned long previousTime = 0; // Variable to store the previous time for checking elapsed time
// Default state: WipOffPark
int currentState = 0;
void setup() {
// Initialize input pins
pinMode(Sw0PotPin, INPUT);
pinMode(Sw1OffParkPin, INPUT);
pinMode(Sw1IntmPin, INPUT);
pinMode(Sw1LoPin, INPUT);
pinMode(Sw1HiPin, INPUT);
// Initialize output pins
pinMode(Rly1LoPin, OUTPUT);
pinMode(Rly2HiPin, OUTPUT);
pinMode(Rly3GndPin, OUTPUT);
pinMode(Rly4WshPin, OUTPUT);
// Default state: all relays off (WipOffPark)
digitalWrite(Rly1LoPin, LOW);
digitalWrite(Rly2HiPin, LOW);
digitalWrite(Rly3GndPin, HIGH);
digitalWrite(Rly4WshPin, HIGH);
}
void loop() {
// Read input states
int offParkState = digitalRead(Sw1OffParkPin);
int intmState = digitalRead(Sw1IntmPin);
int loState = digitalRead(Sw1LoPin);
int hiState = digitalRead(Sw1HiPin);
// Check input states and execute corresponding functions
if (offParkState == HIGH) {
WipOffPark();
currentState = 0; // Set current state to WipOffPark
} else if (intmState == HIGH) {
if (!isWipIntmRunning) {
WipIntm();
currentState = 1; // Set current state to WipIntm
}
} else if (loState == HIGH) {
WipLo();
currentState = 2; // Set current state to WipLo
} else if (hiState == HIGH) {
WipHi();
currentState = 3; // Set current state to WipHi
} else {
// Stop WipIntm function if no input is detected
if (currentState == 1 && isWipIntmRunning) {
isWipIntmRunning = false;
digitalWrite(Rly3GndPin, HIGH);
}
}
// Update waiting time based on potentiometer value
int potValue = analogRead(Sw0PotPin);
waitingTime = map(potValue, 0, 1023, 5000, 30000); // 5 seconds to 30 seconds
// Check if the waiting time has elapsed for WipIntm function
if (currentState == 1 && isWipIntmRunning && millis() - previousTime >= waitingTime) {
previousTime = millis(); // Update the previous time for the next waiting period
digitalWrite(Rly3GndPin, LOW);
delay(1000);
digitalWrite(Rly3GndPin, HIGH);
}
}
void WipOffPark() {
digitalWrite(Rly1LoPin, LOW);
digitalWrite(Rly2HiPin, LOW);
digitalWrite(Rly3GndPin, HIGH);
digitalWrite(Rly4WshPin, HIGH);
}
void WipIntm() {
isWipIntmRunning = true; // Set the flag to indicate that WipIntm function is running
digitalWrite(Rly1LoPin, LOW);
digitalWrite(Rly2HiPin, LOW);
digitalWrite(Rly3GndPin, HIGH);
digitalWrite(Rly4WshPin, HIGH);
while (digitalRead(Sw1IntmPin) == HIGH && isWipIntmRunning) {
// WipIntm function code
int potValue = analogRead(Sw0PotPin);
waitingTime = map(potValue, 0, 1023, 5000, 30000); // Update waiting time based on potentiometer value
unsigned long currentTime = millis();
if (currentTime - previousTime >= waitingTime) {
previousTime = currentTime;
digitalWrite(Rly3GndPin, LOW);
delay(1000);
digitalWrite(Rly3GndPin, HIGH);
}
}
isWipIntmRunning = false; // Reset the flag after the loop ends
digitalWrite(Rly3GndPin, HIGH);
}
void WipLo() {
digitalWrite(Rly1LoPin, LOW);
digitalWrite(Rly2HiPin, LOW);
digitalWrite(Rly3GndPin, LOW);
digitalWrite(Rly4WshPin, HIGH);
}
void WipHi() {
digitalWrite(Rly1LoPin, HIGH);
digitalWrite(Rly2HiPin, LOW);
digitalWrite(Rly3GndPin, LOW);
digitalWrite(Rly4WshPin, HIGH);
}