Below is the error I am getting.
I am going nuts because I cant find the problem in my code.
I written 2 functions (1 forward, 1 for reverse) for my 28byj-48 motor to run.
Please help me to solve this problem. I am using arduino Uno
THanks!
G:\arduino program\adx335stepper-noavarage\adx335stepper-noavarage.ino: In function 'void loop()':
adx335stepper-noavarage:139:3: error: 'Onestep' was not declared in this scope
Onestep(true);
^~~~~~~
G:\arduino program\adx335stepper-noavarage\adx335stepper-noavarage.ino:139:3: note: suggested alternative: 'OneStep'
Onestep(true);
^~~~~~~
OneStep
exit status 1
'Onestep' was not declared in this scope
This is my Code
#define ADC_ref 5 // ADC reference Voltage
#define zero_x 1.799
#define zero_y 1.799
#define zero_z 1.799
#define STEPPER_PIN_1 2
#define STEPPER_PIN_2 3
#define STEPPER_PIN_3 4
#define STEPPER_PIN_4 5
#define sensitivity_x 0.45
#define sensitivity_y 0.45
#define sensitivity_z 0.45
unsigned int value_x;
unsigned int value_y;
unsigned int value_z;
float xv;
float yv;
float zv;
float angle;
float xm;
const int numReadings = 3;
int readings[numReadings];
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int xmap = 0;
int curxmap;
int oldxmap=0;
int posxstep = 0;
int stepxmap = 0;
int step_number =0;
void setup()
{
pinMode(STEPPER_PIN_1, OUTPUT);
pinMode(STEPPER_PIN_2, OUTPUT);
pinMode(STEPPER_PIN_3, OUTPUT);
pinMode(STEPPER_PIN_4, OUTPUT);
Serial.begin(9600);
}
void Rstep(bool dir){
if(dir){
switch(step_number){
case 0:
digitalWrite(STEPPER_PIN_1, HIGH);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, HIGH);
break;
case 1:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, HIGH);
digitalWrite(STEPPER_PIN_4, HIGH);
break;
case 2:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, HIGH);
digitalWrite(STEPPER_PIN_3, HIGH);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 3:
digitalWrite(STEPPER_PIN_1, HIGH);
digitalWrite(STEPPER_PIN_2, HIGH);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
}
}
step_number++;
if(step_number > 3){
step_number = 0;
}
}
void OneStep(bool dir){
if(dir){
switch(step_number){
case 0:
digitalWrite(STEPPER_PIN_1, HIGH);
digitalWrite(STEPPER_PIN_2, HIGH);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 1:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, HIGH);
digitalWrite(STEPPER_PIN_3, HIGH);
digitalWrite(STEPPER_PIN_4, LOW);
break;
case 2:
digitalWrite(STEPPER_PIN_1, LOW);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, HIGH);
digitalWrite(STEPPER_PIN_4, HIGH);
break;
case 3:
digitalWrite(STEPPER_PIN_1, HIGH);
digitalWrite(STEPPER_PIN_2, LOW);
digitalWrite(STEPPER_PIN_3, LOW);
digitalWrite(STEPPER_PIN_4, HIGH);
break;
}
}
step_number++;
if(step_number > 3){
step_number = 0;
}
}
void loop()
{
value_x = analogRead(A0);
value_y = analogRead(A1);
value_z = analogRead(A2);
xv=(((value_x/1024.0*ADC_ref-zero_x)/sensitivity_x)+0.15)*(360/3.1416);
yv=(((value_y/1024.0*ADC_ref-zero_y)/sensitivity_y)+0.15)*(360/3.1416);
zv=(((value_z/1024.0*ADC_ref-zero_z)/sensitivity_z)+0.4)*(180/3.1416);
xm = map(xv,-95,80,0,180);
curxmap = map(xm, 0, 180, 0, 2048);
stepxmap=oldxmap-curxmap;
posxstep = abs(stepxmap);
if(curxmap>oldxmap ){
for (int x = 0; x<posxstep; x++){
Onestep(true);
delay(2);
}
}
else {
for (int x = 0; x<posxstep; x++){
Rstep(true);
delay(2);
}
}
oldxmap=curxmap;
Serial.println("\t");
Serial.print("xv value = ");
Serial.print(xv);
Serial.println("\t");
Serial.print("curxmap value = ");
Serial.print(curxmap);
Serial.println("\t");
Serial.print("oldxmap value = ");
Serial.print(oldxmap);
Serial.println("\t");
Serial.print("yv value = ");
Serial.print(yv);
Serial.println("\t");
Serial.print("zv value = ");
Serial.print(zv);
Serial.println(" ");
Serial.println("\t");
delay(2);
}