Hi i'm a beginner and having some trouble with an assignment. How would you adjust the delay of a led using a potentiometer I'm not sure how to code it. Any help appreciated
What did the teacher explain about potentiometers and possibly analogRead() on your arduino?
J-M-L:
What did the teacher explain about potentiometers and possibly analogRead() on your arduino?
we've gone over analogread() and i have my arduino set on A0 right now I just don't know how to use a pot to chang e a delay. he also said to use the map function to do this. this is some of my code right now
int potValue = 0;
int pushbuttonState = 0;
int inpin = 7;
int SensorValue = 0;
void setup()
{
Serial.begin(9600);
pinMode(A0, INPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
}
void loop(){
digitalWrite(8, HIGH);
digitalWrite(13, HIGH);
// pushbutton for pedestrians to walk
pushbuttonState = digitalRead(inpin);
// Potentiometer delay to green light, if potentiometer is high it will delay for longer and if low it will delay for a shorter period
SensorValue = map(analogRead(A0), 0, 1023, 0, 127);
// if pushbutton is being pressed the light will change from red to green after a 2 second delay
I just don't know how to use a pot to chang e a delay..
Well a POT is like.. Err.. A trombone! Slide the thing in and out and it goes from a low note to a high note. Got that? Now POT has 3 connectors. Hook one side to low (ground) and the other side to high (5V). Then the middle connector go from ground to 5 Volts as you turn the knob. Hook the middle wire to A0 then just do
void loop() {
Serial.println(analogRead(A0));
}
printing the result of reading A0 for a bit to see if it works.
If you get that to work, then you'll need to find out how much delay they are looking for.
Good luck.
-jim lee
Take the blink example.
You’ll see there is a delay when you light up the led and another one when it’s off
The value used in the delay is a fixed number here but nothing prevents you to use a variable.
The value of that variable could come from... that varies between 0 and 1023
The range of that variable could be set by using .... in the right way
Just need to put things together and use code tags (read forum rules) to post code
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.