LaurensHuizer / Arduino

Object Oriented Programming for Arduino
GNU General Public License v3.0
10 stars 8 forks source link

StepperMotor.h: 'ISO C++ forbids initialization of member '_mode'' (and others) #1

Open leggler opened 8 years ago

leggler commented 8 years ago

Hey Laurens!

I found your peace of code from the comments of http://www.instructables.com/id/BYJ48-Stepper-Motor/ . The code described there workes fine with me, but I agree that the object orientet options seems smarter, so thanks for the work! However, I cant get it running. When trying the example provided in the StepperMotor library, I get the following error. I checked if it was an import-issue (files in the wrong folder, etc.) but this does not seem to be the case...

Thanks! Lukas

Arduino: 1.0.6 (Mac OS X), Board: "Arduino Uno" In file included from Example.ino:44: /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:74: error: ISO C++ forbids initialization of member '_mode' /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:74: error: making '_mode' static /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:74: error: ISO C++ forbids in-class initialization of non-const static member '_mode' /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:75: error: ISO C++ forbids initialization of member '_steps' /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:75: error: making '_steps' static /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:75: error: ISO C++ forbids in-class initialization of non-const static member '_steps' /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:76: error: ISO C++ forbids initialization of member '_delayMs' /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:76: error: making '_delayMs' static /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:76: error: ISO C++ forbids in-class initialization of non-const static member '_delayMs' /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:77: error: ISO C++ forbids initialization of member '_engineStep' /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:77: error: making '_engineStep' static /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:77: error: ISO C++ forbids in-class initialization of non-const static member '_engineStep' /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:78: error: ISO C++ forbids initialization of member '_currentStep' /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:78: error: making '_currentStep' static /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:78: error: ISO C++ forbids in-class initialization of non-const static member '_currentStep' /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:79: error: ISO C++ forbids initialization of member '_rotationDirection' /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:79: error: making '_rotationDirection' static /Users/lks/Documents/Arduino/libraries/StepperMotor/StepperMotor.h:79: error: ISO C++ forbids in-class initialization of non-const static member '_rotationDirection'

LaurensHuizer commented 8 years ago

Hi Lukas,

This is very strange... it seems like the Mac software version cannot handle the direct initialization of the variables. Can you try the following:

Change StepperMotor.h and remove the values from the variables (you can copy & paste this): int _mode; int _steps; int _delayMs; int _engineStep; int _currentStep; int _rotationDirection

Next change StepperMotor.cpp and add the initial values to the constructor (you can copy & paste this): StepperMotor::StepperMotor(int pinA, int pinB, int pinC, int pinD) : BaseTimedElement() { _pinA = pinA; _pinB = pinB; _pinC = pinC; _pinD = pinD; pinMode(pinA, OUTPUT); pinMode(pinB, OUTPUT); pinMode(pinC, OUTPUT); pinMode(pinD, OUTPUT); setWaitTimeEvery(_delayMs); _mode = 0; _steps = -1; _delayMs = 1; _engineStep = 0; _currentStep = 0; _rotationDirection = 0; }

leggler commented 8 years ago

Hey Laurens!

Thanks for your quick answer! It seems like this really is a mac/windows problem!

With the suggested code-changes it works perfectly (Note however that a semicolon is missing in the last line of StepperMotor.h changes, the last line should be "int _rotationDirection;" )

Thanks for the good work!