Hi! Its my first time using Arduino and i need to solve the following exercise. While writing the code i had too many doubts to continue, so i could use some help.
"Write a program that receives the speed and desired direction of rotation and sends to a motor the signals that correspond. The input of the angle is done with a potentiometer (slider) , where the top end represents maximum velocity in one direction, and the low end represents maximum velocity in the opposite direction. The middle point stops the motor."
I wrote this code, i just wanted to see another perspective on it. But thanks for the feedback anyway.
I am using UnoArduSim as a simulator to see the code in action, but i just don't understand why nothing happens when i execute the program.
int pwmPin = 12;
int Sentido = 7;
int pot = A0;
int c1 = 0;
int c2 = 0;
Well, since that provides zero information, just concentrate your effort on the slider potentiometer. How do you have it wired? Please show a block diagram. And ONLY work on a program that will read the setting of the potentiometer.
you should post your code as one single code-section
This thread describes very detaild how can re-edit your postings
never used UnoArduSim
What do you expect the program to do?
The things you have posted still make the impression
You want your homework done by others.
I tested your code in UnoArduSim the code works as expected
"Write a program that receives the speed and desired direction of rotation and sends to a motor the signals that correspond. The input of the angle is done with a potentiometer (slider) , where the top end represents maximum velocity in one direction, and the low end represents maximum velocity in the opposite direction. The middle point stops the motor."
Nice programing exercise.
Let look of what you need ...
A potentiometer. The command to read is ... pot_int_value = analogRead(any_analog_chanel);
So after you need to convert the integer value from 0 to 1023 ---> Going CCW - max speed ----> slowing down --- > stop ----> accelerating ---> Going CW - max speed. 0 max CCW speed , 512 - stop - 1023 max CW speed.
A H-Bridge IC - to control a small DC motor with it own PSU. , A Pulse Width chanel to control the speed and a digital output chanel to control the direction.
And beside, that could be use as a Model Train speed / direction controller.
PS ... Please ... when trying to code, use this reference. I use it all the time I code.
I'm quoting myself:
I downloaded UnoArduSim pasted your code into the simulator entered the IO-pin-numbers to the slider-potentiometer and the DC motor and the DC-motor rotates as expected depending on the slider-poti-position.