class Stepper
{
private:
int enable;
int direction;
int speed;
static int turretCounter;
public:
Stepper(int en, int dir)
{
enable = en;
direction = dir;
pinMode(enable,OUTPUT);
pinMode(direction,OUTPUT);
pinMode(4,OUTPUT);
}
void Stop()
{
digitalWrite(enable,1);
Timer1.detachInterrupt();
Timer1.stop();
}
static void IncrementCounter()
{
turretCounter++;
}
//your step pin must be 4 due to limitations on static vars and methods
static void Step()
{
digitalWrite(4,0);
delayMicroseconds(1);
digitalWrite(4,1);
IncrementCounter();
}
void SetSpeed(int Speed)
{
speed = Speed;
}
void Run(int seconds)
{
digitalWrite(enable,0);
Timer1.attachInterrupt(Step);
Timer1.initialize(speed);
}
int GetCounter()
{
return turretCounter;
}
void SetDirection(int dir)
{
digitalWrite(direction,dir);
}
int GetSpeed()
{
return speed;
}
};
정적 Step() 메서드 및 정적 IncrementCounter() 메서드에주의를 환기하고 싶습니다. Step() 함수 내에서 변수를 증가 시키려고 시도했지만 항상 "Arudino Nano 보드에서 컴파일하는 중 오류가 발생합니다". Step() 메서드 내에서 직접 IncrementCounter()를 호출하려고 시도했는데 "개체가없는 클래스 메서드를 호출 할 수 없습니다"오류가 발생합니다. Step() 메서드에서이 오류가 발생합니다.정적 클래스 함수 내에서 정적 변수를 증가시킬 수 없습니다.
* 개체가없는 클래스 메서드를 호출 할 수 없습니다 * 코드에서 오류가 발생한 위치를 가리켜 야합니다. 그 코드는 무엇입니까? – NathanOliver
그 오류는 Step() 메서드에서 발생합니다. @ NathanOliver –