I'm new to ardino so please was not too harsh on my weird code. I'm looking to make a timer that is controlled by two potentiometers. The first should indicate how long it should wait before turning on the power to the relay. The other should specify how long the power should be on. A push button should start the loop.
#define relayPin 8
#define potPin1 A0
#define potPin2 A1
#define startPin 3
#define relayType 'L'
const long maxTime = 10000;
const long minTime = 1000;
long duration;
int potValue1;
int potValue2;
long rememTime;
int relayState =0;
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(startPin, INPUT_PULLUP);
pinMode(potPin1, INPUT);
pinMode(potPin2, INPUT);
if(relayType == 'L')
{
digitalWrite(relayPin, HIGH);
}else{
digitalWrite(relayPin, LOW);
}}
void loop() {
potValue1 = analogRead(1)/10;
duration = map(potValue1, 0, 102, minTime, maxTime);
if(digitalRead(startPin) ==LOW)
{
rememTime = millis();
relayState = 0;
controlRelay();
}
if( (millis()- rememTime) > duration )
{
potValue2 = analogRead(1)/10;
duration = map(potValue1, 0, 102, minTime, maxTime);
}
if( (millis()- rememTime) > duration )
{
rememTime = millis();
relayState = 1;
controlRelay();
}
if( (millis()- rememTime) > duration )
{
relayState = 0;
controlRelay();
}
delay(200);}
void controlRelay()
{
if(relayType == 'L')
{
if(relayState == 1)
{
digitalWrite(relayPin, LOW);
}else{
digitalWrite(relayPin, HIGH);
}
}else{
if(relayState == 1)
{
digitalWrite(relayPin, HIGH);
}else{
digitalWrite(relayPin, LOW);
}
}
}
void reset()
{
duration =0;
if(relayType == 'L')
{
digitalWrite(relayPin, HIGH);
}else{
digitalWrite(relayPin, LOW);
}
}
[color=#202124]My code does not work so I would need help with it.[/color]