Hi.
since im having problems that my "m2-ATX" power supply works in "dumb mode" only, so i thought i could make shutdown timers on arduino.
It is my first attempt to program arduino and it did not go well.
where could be problem in code?
int relay = 2;
int pcpwr = 4;
int acc = A0;
void setup()
{
pinMode(relay, OUTPUT); //master relay
pinMode (pcpwr, OUTPUT); //pc power button
pinMode (acc, INPUT); //acc (car radio state)
Serial.begin(9600);
}
void loop() {
int pcpwrA = digitalRead(pcpwr);
int relayA = digitalRead(relay);
int accA = analogRead(acc);
Serial.println("ACC");
Serial.println(accA);
Serial.println("PCPWR");
Serial.println(pcpwrA);
Serial.println("RELAY");
Serial.println(relayA);
delay(1000);
{
accA = analogRead(acc);
if (accA > 1000)
{
digitalWrite(relay, HIGH); //keeps relay on when key turned to radio state
}
if (accA < 1000 and digitalRead(relay) == HIGH)
{
delay(1200); //if acc goes low, waits Xminutes then turns off pc
digitalWrite(pcpwr, HIGH); //should keep pc power button shorted for 1 second
delay(1000);
Serial.println("power button");
digitalWrite(pcpwr, LOW);
delay(3000);
digitalWrite(relay, LOW); //master relay off after pc is turned off
}
else {}
}
}
}
}