
求大神看看代码出什么问题了?
#include <AccelStepper.h>
#include <AFMotor.h>
#define encoderpinA 53
#define encoderpinB 51
int encoderpos = 0;
int encoderpinAlast = LOW;
int encoderpinBlast = LOW;
int n = LOW;
AF_Stepper motor2(48, 2);
void forwardstep2() {
motor2.onestep(FORWARD,SINGLE);
}
void backwardstep2() {
motor2.onestep(BACKWARD,SINGLE);
}
AccelStepper stepper2(forwardstep2, backwardstep2);
void setup()
{
pinMode(encoderpinA,INPUT_PULLUP);
pinMode(encoderpinB,INPUT_PULLUP);
}
void loop()
{
n = digitalRead(encoderPinA);
if((encoderPinAlast !=n)){
if(((n == HIGH) && (digitalRead(encoderPinB == LOW)) ||
((n == LOW) && (digitalRead(encoderPinB == HIGH))) {
motor.step(100,FORWARD,MICROSTEP);
} else {
motor.step(100,FORWARD,MICROSTEP);
}
} else {
n = digitalRead(encoderPinB);
if((encoderPinBlast !=n)){
if(((n == HIGH) && (digitalRead(encoderPinA == LOW)) ||
((n == LOW) && (digitalRead(encoderPinA == HIGH))) {
motor.step(100,FORWARD,MICROSTEP);
} else {
motor.step(100,FORWARD,MICROSTEP);
}
}
}
encoderPinAlast = digitalRead(endcoderPinA)
encoderPinBlast = digitalRead(endcoderPinB)
}
自己修改了些.....但还是有很多错误提示:
__.ino: In function *void loop()*:
__.ino:31:19: error: *encoderPinA* was not declared in this scope
__.ino:32:6: error: *encoderPinAlast* was not declared in this scope
__.ino:33:37: error: *encoderPinB* was not declared in this scope
__.ino:34:59: error: expected *)* before *{* token
__.ino:36:10: error: expected *)* before *else*
__.ino:39:3: error: expected primary-expression before *}* token
__.ino:39:3: error: expected *;* before *}* token
__.ino:40:21: error: *encoderPinB* was not declared in this scope
__.ino:41:10: error: *encoderPinBlast* was not declared in this scope
__.ino:43:59: error: expected *)* before *{* token
__.ino:45:10: error: expected *)* before *else*
__.ino:48:6: error: expected primary-expression before *}* token
__.ino:48:6: error: expected *;* before *}* token
__.ino:50:3: error: *encoderPinAlast* was not declared in this scope
__.ino:50:33: error: *endcoderPinA* was not declared in this scope
__.ino:51:3: error: expected *;* before *encoderPinBlast*
#include <AccelStepper.h>
#include <AFMotor.h>
#define encoderpinA 53
#define encoderpinB 51
int encoderpos = 0;
int encoderpinAlast = LOW;
int encoderpinBlast = LOW;
int n = LOW;
AF_Stepper motor2(48, 2);
void forwardstep2() {
motor2.onestep(FORWARD,SINGLE);
}
void backwardstep2() {
motor2.onestep(BACKWARD,SINGLE);
}
AccelStepper stepper2(forwardstep2, backwardstep2);
void setup()
{
pinMode(encoderpinA,INPUT_PULLUP);
pinMode(encoderpinB,INPUT_PULLUP);
}
void loop()
{
n = digitalRead(encoderPinA);
if((encoderPinAlast !=n)){
if(((n == HIGH) && (digitalRead(encoderPinB == LOW)) ||
((n == LOW) && (digitalRead(encoderPinB == HIGH))) {
motor.step(100,FORWARD,MICROSTEP);
} else {
motor.step(100,FORWARD,MICROSTEP);
}
} else {
n = digitalRead(encoderPinB);
if((encoderPinBlast !=n)){
if(((n == HIGH) && (digitalRead(encoderPinA == LOW)) ||
((n == LOW) && (digitalRead(encoderPinA == HIGH))) {
motor.step(100,FORWARD,MICROSTEP);
} else {
motor.step(100,FORWARD,MICROSTEP);
}
}
}
encoderPinAlast = digitalRead(endcoderPinA)
encoderPinBlast = digitalRead(endcoderPinB)
}
自己修改了些.....但还是有很多错误提示:
__.ino: In function *void loop()*:
__.ino:31:19: error: *encoderPinA* was not declared in this scope
__.ino:32:6: error: *encoderPinAlast* was not declared in this scope
__.ino:33:37: error: *encoderPinB* was not declared in this scope
__.ino:34:59: error: expected *)* before *{* token
__.ino:36:10: error: expected *)* before *else*
__.ino:39:3: error: expected primary-expression before *}* token
__.ino:39:3: error: expected *;* before *}* token
__.ino:40:21: error: *encoderPinB* was not declared in this scope
__.ino:41:10: error: *encoderPinBlast* was not declared in this scope
__.ino:43:59: error: expected *)* before *{* token
__.ino:45:10: error: expected *)* before *else*
__.ino:48:6: error: expected primary-expression before *}* token
__.ino:48:6: error: expected *;* before *}* token
__.ino:50:3: error: *encoderPinAlast* was not declared in this scope
__.ino:50:33: error: *endcoderPinA* was not declared in this scope
__.ino:51:3: error: expected *;* before *encoderPinBlast*
