int ena = 5;
int in1 = 4;
int in2 = 3;
int mspeed = 255;
void setup();
pinMode(ena,OUTPUT);
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
void loop();
digitalWrite(ena,HIGH);
digitalWrite(in1,HIGH);
digitalWrite(in2,LOW);
Serial.begin(9600);
analogWrite(ena,mspeed);
I don’t know why but my motor is not running I made the right connections but it won’t work!Is there anything wrong with this code?
It wont work because you have a lot of syntax errors and the code is incomplete so the code will not even compile. If there are errors at compile time you should tell us that and post the errors. Post the entire text of the errors, do not paraphrase.
Yes there is.
zamastercoder1813:
void setup();
Lose the ; (semi-colon).
You need to enclose the code for the setup() function in curly brackets .
You need to enclose the code for the loop() function in curly brackets.
It is not an error, just poor practice, to put Serial.begin() in loop. Put it in setup() because it only needs to be called one time.
Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Pleasecan go back and fix your original post .
Here is your code with the above problems fixed, indented with the AutoFormat and posted, properly, in a code block so that it is easily copied.
int ena = 5;
int in1 = 4;
int in2 = 3;
int mspeed = 255;
void setup()
{
Serial.begin(9600);
pinMode(ena, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
}
void loop()
{
digitalWrite(ena, HIGH);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(ena, mspeed);
}
Does it load work now?
1 Like
gcjr
June 13, 2023, 7:53pm
3
groundFungus:
digitalWrite(ena, HIGH);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
analogWrite(ena, mspeed);
setting ena HIGH with digitalWrite() and to mspeed
with analogWrite(), as suggested in the original code are redundant.
if mspeed
were something different (lower) than 255, the digitalWrite() would interfere. the digitalWrite() should be deleted
groundFungus:
digitalWrite(ena, HIGH);
Quite right, I did miss that. Thanks.
and
groundFungus:
pinMode(ena, OUTPUT);
Is not required or desirable.
gcjr
June 13, 2023, 7:58pm
5
is the pinMode (ena, OUTPUT) needed?
No, see my previous post. I got it in at the same time you posted.
system
Closed
December 10, 2023, 7:59pm
7
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.