int potPin = A0;
int motorPin = 9;
int potValue = 0;
int motorValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
potValue = analogRead(potPin);
motorValue = map(potValue, 0, 1023, 0, 255);
analogWrite(motorPin, motorValue);
Serial.print("potentiometer = " );
Serial.print(potValue);
Serial.print("\t motor = ");
Serial.println(motorValue);
delay(2);
}
Have you looked up any of the lines using the Reference page?
yes, but I cant quite connect all of the terms together... This is for a school project and we need to control a DC motor with a potentiometer in terms of speed with arduino. Part of the project is to explain the code.
Duplicate thread deleted.
DO NOT CROSS-POST
int potPin = A0; // declare a variable twice as big as it should be, and should be a const
int motorPin = 9; // ditto
int potValue = 0; // declare a variable and initialise it to zero, which the compiler would do for you anyway
int motorValue = 0; // ditto
int potPin = A0; //address A0 as something more intuitive, in this case potPin
int motorPin = 9; //same here if(motorPin == HIGH) is the same as if(digitalRead(9) == HIGH)
int potValue = 0;
int motorValue = 0;
void setup() //code that runs once (on start up) inside the brackets
{
Serial.begin(9600); //initialize serial communication at 9600 baud (lets you use your serial port)
}
void loop() //loops inside these brackets repeatedly (main program)
{
potValue = analogRead(potPin); //record the voltage on analog pin 0. stores a value between 0-1023. //each value corresponds to ~.00488 volts
motorValue = map(potValue, 0, 1023, 0, 255); // remaps 0-1023 to 0 -255, usually for PWM output
analogWrite(motorPin, motorValue); //Pulse width modulate pin 9 the re-scaled value above
Serial.print("potentiometer = " ); //print this in the serial monitor
Serial.print(potValue); //print the vaule stored in this variable
Serial.print("\t motor = "); //(tabbed over) print "motor =" in serial monitor
Serial.println(motorValue); //print the vaule stored in this variable
delay(2); //wait 2ms before looping back around
}
p123abc:
This is for a school project
Part of the project is to explain the code.
I thought that meant YOU had to provide the explanation - not get someone else to do your homework for you.
By all means ask one or two specific questions but not "please do the whole thing"
...R
Thanks, and one more thing, how does having all of this have to do with having the potentiometer move the motor.
(I am very inexperienced with arduino and do not really get any of the terms used in class)
And this is, btw a portion of the whole project. I already wired, schemed, and wrote instructions on how to create the circuit... this is the last part.
And this is, btw a portion of the whole project. ..... this is the last part.
So you are only cheating a little then. Does that make it OK?
Again, we are allowed to use online sources, which is how i got the approved code in the first place.
p123abc:
Again, we are allowed to use online sources,
A forum is not an online source. A source is something like a Wikipedia page. Information that you read and understand in order to do your assignment. In education terms this is a good thing.
However this forum is not a source it is a resource, and you are getting people to do the work for you. Did you spot the jokes in what you were told? Possibly not because I think you have no idea about what you are doing.
I used to be ( what you in the U.S. call ) a professor at a University and I can tell you that what you are doing IS cheating. You did not ask about how the code worked you asked for a line by line explanation which was exactly what you are asked in your project to do.
which is how i got the approved code in the first place.
That makes things even worse.
Thanks for clarifying
I already wired, schemed, and wrote instructions on how to create the circuit
You did all this, and still have no clue what the program is doing?
jremington:
You did all this, and still have no clue what the program is doing?
Yes. I had exactly the same thought.
If true, it does not justify a pass grade.
A few days of reading and studying seems to be indicated.
...R
if(motorPin == HIGH)
Never gonna happen. ![]()
Hi,
AWOL:
if(motorPin == HIGH)Never gonna happen.
Where????
p123abc Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?
Tom...... ![]()
Where?
In the code comments by dustin02rsx
Maybe it was his way of making sure some marks were lost, along with some other comments.
Well, gosh,,, '9' is pretty HIGH, if you're a zero.......
In the time spent trying to get somebody else to do his work, he could have learned a lot more by going to the reference page and maybe the playground..........................................