I created Step Motor and Led System. I have got to much codes in Arduino. I want to define part part. How can I do it? Such as.. I want to define this chapter name of "stepname" and I want this >if "stepname" is 1, It do this chapter..<
if(stepsname == 1){
digitalWrite(dirPin, HIGH);
for (int i = 0; i < 0.5*stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
Serial.println("↓50");
}
I defined it likes this.. I need help. What can I use for this chapter. Could you rewrite for me?
UKHeliBob:
Do you mean that you have run out of memory or that you just want to tidy up the program ?
I am using Arduino and Processing for my system. I put Buttons on Processing. I can't use Buttons together. I must organize Arduino codes. I will define chapter and I will use defined codes. I clicked Buttons but not working at the momnet. It waits to end of process for work other buttons. I want to use together all Buttons.
Can you try and get your words right. You use the word "chapter" this has no place in the language of programming in C. It seems like you may want to use the word "variable" because that is what the compiler is talking about when it says "not in scope".
That is not ALL your code.
We need to see it all. You have no setup function.
It is likely that you defined the stepsname variable in the setup function. If so it is only valid or in scope in the setup function. It has to be defined outside any function to be in scope in all functions.
Grumpy_Mike:
Can you try and get your words right. You use the word "chapter" this has no place in the language of programming in C. It seems like you may want to use the word "variable" because that is what the compiler is talking about when it says "not in scope".
That is not ALL your code.
We need to see it all.
My codes interrupt. I need help to rewrite.
int dirPin = 2;
int stepPin = 3;
int ledPin = 4;
int fanPin = 5;
int incomingByte = 0;
int stepsname = 1;
int stepsPerRevolution = 400;
void setup() {
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(fanPin, OUTPUT);
Serial.begin(9600);
Serial.println("Press 9 to FAN INAKTIVE");
Serial.println("Press 8 to FAN AKTIVE");
Serial.println("Press 7 to ↓50");
Serial.println("Press 6 to ↑50");
Serial.println("Press 5 to GO HOME");
Serial.println("Press 4 to LED OFF");
Serial.println("Press 3 to LED ON");
Serial.println("Press 2 to StepMotor STOP");
Serial.println("Press 1 to StepMotor >");
Serial.println("Press 0 to StepMotor <");
}
void loop() {
if (Serial.available() > 0) {
incomingByte = Serial.read();
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(incomingByte == '9'){
digitalWrite(fanPin, LOW);
Serial.println("FAN INAKTIVE");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(incomingByte == '8'){
digitalWrite(fanPin, HIGH);
Serial.println("FAN AKTIVE");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(incomingByte == '7'){
stepsname = 1;
stepsname = 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(incomingByte == '6'){
stepsname = 1;
stepsname = 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(incomingByte == '5'){
digitalWrite(dirPin, LOW);
for (int i = 4; i < 4*stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
Serial.println("GO HOME");
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(incomingByte == '4'){
digitalWrite(ledPin, LOW);
Serial.println("LED OFF");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(incomingByte == '3'){
digitalWrite(ledPin, HIGH);
Serial.println("LED ON");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(incomingByte == '2'){
Serial.end();
Serial.println("StepMotor STOP");
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(incomingByte == '1'){
digitalWrite(dirPin, HIGH);
for (int i = 0; i < 1*stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
Serial.println("StepMotor >");
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(incomingByte == '0'){
digitalWrite(dirPin, LOW);
for (int i = 0; i < 1*stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
Serial.println("StepMotor <");
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(stepsname == '1'){
digitalWrite(dirPin, HIGH);
for (int i = 0; i < 0.5*stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
Serial.println("↓50");
if(stepsname == '0'){
for (int i = 0; i < 0*stepsPerRevolution; i++) {
}
}
}
}
if(stepsname == '1'){
digitalWrite(dirPin, LOW);
for (int i = 0; i < 0.5*stepsPerRevolution; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(500);
digitalWrite(stepPin, LOW);
delayMicroseconds(500);
Serial.println("↑50");
if(stepsname == '0'){
for (int i = 0; i < 0.5*stepsPerRevolution; i++) {
}
}
}
}
}
}
Grumpy_Mike:
That code compiles correctly on my computer. It does not give the error you have shown.
Problem is not here. Are you understand my problem? Code is look like correct but not working at the moment. My processing code is right. I'm sure. My problem is Arduino codes. Could you read again my topic?
I am understanding what you talked about in the original post about a variable not being in scope.
You seem to have got over that problem without acknowledging it to us in the forum.
Now it seems you have another problem, that is you are not describing at all in a way that anyone who speaks English as a first language can understand.
The phrase:-
My codes interrupt.
Is meaningless, there is clearly no interrupts going on.
Say what your program does and say what you would want it to do. Use English words. Then, and only then, do we stand a chance of understanding your problem.
Grumpy_Mike:
I am understanding what you talked about in the original post about a variable not being in scope.
You seem to have got over that problem without acknowledging it to us in the forum.
Now it seems you have another problem, that is you are not describing at all in a way that anyone who speaks English as a first language can understand.
The phrase:-Is meaningless, there is clearly no interrupts going on.
Say what your program does and say what you would want it to do. Use English words. Then, and only then, do we stand a chance of understanding your problem.
Grumpy_Mike:
That code compiles correctly on my computer. It does not give the error you have shown.
BerkCil:
Problem is not here.
Please confirm the stepsname undefined problem has gone away for you, OP. You just wasted my time getting set up to test something which you seem (as mentioned above by Grumpy_Mike) to have fixed but not told us.