I am wanting to make a light that when you hit a button the light turns on and stays on for however far the POT is twisted (10sec. to 2 min) but i keep doing something wrong here is my code
int resetPin = 8;
int lightPin = 11;
int lightTime = A0;
void setup()
{
//button that turns the led on
pinMode(resetPin, INPUT);
//the led its self
pinMode(lightPin, OUTPUT);
//the POT im using to change the time
pinMode(lightTime, INPUT);
}
void loop()
{
lightTime = map(lightTime,0,1024,10000,120000);
}
if (digitalRead(resetPin) == HIGH);
{
digitalWrite(lightPin, HIGH);
Delay(lightTime);
digitalWrite(lightPin, LOW);
}
else
{
lightPin == LOW;
}
You have a pot, a led. OK. Let say you set for 1 minute, the led stay on for 1 min. You turn the pot for 30 sec amd the led stay on for 30 sec. And you want to press a switch to turn on the led.
I still don't know how you wired up your circuit. I hope it is OK.
// your are ok here
int resetPin = 8;
int lightPin = 11;
int lightTime = A0;
void setup()
{
//button that turns the led on
pinMode(resetPin, INPUT);
//the led its self
pinMode(lightPin, OUTPUT);
//the POT im using to change the time
pinMode(lightTime, INPUT); // <-- bug one. Pot usage is analog pin.
}
void loop()
{
// missing a analog read here. Bug no 2
lightTime = map(lightTime,0,1024,10000,120000);
} // <-- bad location , you just close the loop here. Bug no 3
if (digitalRead(resetPin) == HIGH);
{
digitalWrite(lightPin, HIGH);
Delay(lightTime);
digitalWrite(lightPin, LOW);
}
else
{
lightPin == LOW;
}
// <-- missing an }. Bug no 4
ok thanks for all the help but i got one more error with the else it the end
int resetPin = 8;
int lightPin = 11;
int lightTime = A0;
void setup()
{
//button that turns the led on
pinMode(resetPin, INPUT);
//the led its self
pinMode(lightPin, OUTPUT);
//the POT im using to change the time
}
void loop()
{
analogRead(lightTime);
lightTime = map(lightTime,0,1024,10000,120000);
if (digitalRead(resetPin) == HIGH);
{
digitalWrite(lightPin, HIGH);
delay(lightTime);
digitalWrite(lightPin, LOW);
}
else
{
digitalWrite(lightPin, LOW);
}
}
if (digitalRead(resetPin) == HIGH); // <<<<---- Remove the ";"
{
digitalWrite(lightPin, HIGH);
delay(lightTime);
digitalWrite(lightPin, LOW);
}
else
{...}
The semicolon ends the if-statement - so all you're telling your arduino is:
if (something) {doNothing;}
So the compiler does not know what to do with the "else".