P1A2
April 8, 2023, 4:28pm
1
can some one please help with the attached cod as it is driving me mad
after sorting out all the bugs and getting to upload to the uno the stepper motor will not run?
but it i remove the if else part the motor runs fine?
thanks Paul
if else.ino (904 Bytes)
Please post your code, in code tags.
Hello P1A2
Welcome to the worldbest forum.
We need some additional information.
Post your sketch, well formated, with well-tempered comments and in so called code tags "< code >" and schematic to see how we can help.
Have a nice day and enjoy coding in C++.
Welcome to the forum
Please post your code here, using < CODE/ > tags when you do
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination
See also FAQ - Arduino Forum for general rules on forum behaviour and etiquette.
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is fru…
P1A2
April 8, 2023, 4:37pm
7
Do you want live notifications when people reply to your posts? Enable Notifications
Custom dashboards, smartphone remote control, data sharing between boards, remote uploads. Get them (for free) using your forum account!
Help why wont this cod work
Using Arduino
Programming Questions
Apr 8
6m
P1A2
2
7mpost #1
can some one please help with the attached cod as it is driving me mad
after sorting out all the bugs and getting to upload to the uno the stepper motor will not run?
but it i remove the if else part the motor runs fine?
thanks
```
t code for the forum`
[if else.ino|attachment](upload://mGUxpxx4f0PpRarEqtFrbbc3OVs.ino) (904 Bytes)
In the IDE, right click and select Copy for Forum. In a new post paste what the IDE has put on the clipboard and it will include the < CODE/ > tags for you. Save the new post
P1A2
April 8, 2023, 4:49pm
9
type or paste code here
if else.ino (904 Bytes)
thanks i think i've got it
int switchpin2 = 11;
digitalRead(switchpin2); //read the state of switchpin2 and ignore it
if (switchpin2 > HIGH) //the value of switchpin2 will still be 11
{
Note my added comments
Test the value returned by digitalRead(switchpin2) not the value of switchpin2 itself which will not have changed
P1A2
April 8, 2023, 5:25pm
12
[quote="SemperIdem, post:10, topic:1112700"]
Like this
int dirpin = 4;
int pulsepin = 5;
int enablepin = 3;
int switchpin1 = 10;
int switchpin2 = 11;
int clockwise = 0;
int counterclockwise = 1;
void setup (){
pinMode(dirpin,OUTPUT);
pinMode(pulsepin, OUTPUT);
pinMode(enablepin, OUTPUT);
pinMode(switchpin1, INPUT);
pinMode(switchpin2, INPUT);
spin(counterclockwise.3.200);
}
void loop(){
}
void spin (int direction, int dly, int steps){
digitalRead(switchpin1){
if (switchpin1>HIGH);
digitalWrite(enablepin,HIGH);
}else if (switchpin1>LOW){
(digitalWritw(enablepin,LOW));
digitalRead(switchpin2);
if (switchpin2>HIGH){
(digitalWrite(dirpin,HIGH));
} else (switckpin2>LOW);
digitalWrite(dirpin,LOW);
}
for (int step = 1,steps< steps +1.steps++);
digitalWrite(pulsepin,LOW);
delay(1);
digitalWrite(pulsepin,HIGH);
delay(dly);
digitalWrite(enablepin,LOW);
}Use code tags to format code for the forum
P1A2:
if (switchpin1>HIGH);
11 (switchPin) is always greater than 1(HIGH)
Lose the semicolon.
Didn't the compiler complain?
Again, lose the semicolon.
And the commas.
gcjr
April 8, 2023, 6:03pm
14
click the <CODE/> icon and post the code in the highlighted area
int dirpin = 4;
int pulsepin = 5;
int enablepin = 3;
int switchpin1 = 10;
int switchpin2 = 11;
int clockwise = 0;
int counterclockwise = 1;
void setup ()
{
pinMode (dirpin,OUTPUT);
pinMode (pulsepin, OUTPUT);
pinMode (enablepin, OUTPUT);
pinMode (switchpin1, INPUT);
pinMode (switchpin2, INPUT);
spin (counterclockwise.3.200);
}
void loop (){
}
void spin (int direction, int dly, int steps)
{
digitalRead (switchpin1) {
if (switchpin1>HIGH);
digitalWrite (enablepin,HIGH);
}
else if (switchpin1>LOW) {
(digitalWritw (enablepin,LOW));
digitalRead (switchpin2);
if (switchpin2>HIGH) {
(digitalWrite (dirpin,HIGH));
}
else
(switckpin2>LOW);
digitalWrite (dirpin,LOW);
}
for (int step = 1,steps< steps +1.steps++)
;
digitalWrite (pulsepin,LOW);
delay (1);
digitalWrite (pulsepin,HIGH);
delay (dly);
digitalWrite (enablepin,LOW);
}
looks like spin would get executed once in setup()
not sure what the following intends to do. looks like the brace, "{", shoudl be after the if, replacing the semicolon, ";"
digitalRead (switchpin1) {
if (switchpin1>HIGH);
digitalWrite (enablepin,HIGH);
}
else if (switchpin1>LOW) {
should this be an else if?
else
(switckpin2>LOW);
digitalWrite (dirpin,LOW);
is this for loop missing braces? the semicolon is the body of the loop
for (int step = 1,steps< steps +1.steps++)
;
what is it intended to do?
system
Closed
October 5, 2023, 6:24pm
16
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.