用的arduinoIDE,开发板是arduino Nano,MX1508库
麻烦给指导一下 错误码 D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino: In function 'void setup()': D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:48:13: error: 'class MX1508' has no member named 'setSpeed' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:49:14: error: 'class MX1508' has no member named 'setSpeed' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino: In function 'void SMBillyBass()': D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:73:19: error: 'class MX1508' has no member named 'halt' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:74:20: error: 'class MX1508' has no member named 'halt' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino: In function 'void openMouth()': D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:111:14: error: 'class MX1508' has no member named 'halt' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:112:14: error: 'class MX1508' has no member named 'setSpeed' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:113:14: error: 'class MX1508' has no member named 'forward' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino: In function 'void closeMouth()': D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:117:14: error: 'class MX1508' has no member named 'halt' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:118:14: error: 'class MX1508' has no member named 'setSpeed' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:119:14: error: 'class MX1508' has no member named 'backward' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino: In function 'void articulateBody(bool)': D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:129:19: error: 'class MX1508' has no member named 'forward' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:134:19: error: 'class MX1508' has no member named 'forward' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:139:19: error: 'class MX1508' has no member named 'forward' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:143:19: error: 'class MX1508' has no member named 'halt' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:144:19: error: 'class MX1508' has no member named 'setSpeed' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:145:19: error: 'class MX1508' has no member named 'backward' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:150:19: error: 'class MX1508' has no member named 'forward' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:155:15: error: 'class MX1508' has no member named 'setSpeed' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:158:17: error: 'class MX1508' has no member named 'halt' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino: In function 'void flap()': D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:166:13: error: 'class MX1508' has no member named 'setSpeed' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:167:13: error: 'class MX1508' has no member named 'backward' D:\资料\鱼文件\BTBillyBass-master\BTBillyBass\BTBillyBass.ino:169:13: error: 'class MX1508' has no member named 'halt' 使用 1.0.0 版本的 MX1508 库,在列出的文件夹中:C:\Users\HU\Documents\Arduino\libraries\MX1508 exit status 1 Compilation error: 'class MX1508' has no member named 'setSpeed' 主文件 #include MX1508 bodyMotor(6, 9); // Sets up an MX1508 controlled motor on PWM pins 6 and 9 MX1508 mouthMotor(5, 3); // Sets up an MX1508 controlled motor on PWM pins 5 and 3 int soundPin = A0; // Sound input int silence = 12; // Threshold for "silence". Anything below this level is ignored. int bodySpeed = 0; // body motor speed initialized to 0 int soundVolume = 0; // variable to hold the analog audio value int fishState = 0; // variable to indicate the state Billy is in bool talking = false; //indicates whether the fish should be talking or not //these variables are for storing the current time, scheduling times for actions to end, and when the action took place long currentTime; long mouthActionTime; long bodyActionTime; long lastActionTime; void setup() { //make sure both motor speeds are set to zero bodyMotor.setSpeed(0); mouthMotor.setSpeed(0); //input mode for sound pin pinMode(soundPin, INPUT); Serial.begin(9600); } void loop() { currentTime = millis(); //updates the time each time the loop is run updateSoundInput(); //updates the volume level detected SMBillyBass(); //this is the switch/case statement to control the state of the fish } void SMBillyBass() { switch (fishState) { case 0: //START & WAITING if (soundVolume > silence) { //if we detect audio input above the threshold if (currentTime > mouthActionTime) { //and if we haven't yet scheduled a mouth movement talking = true; // set talking to true and schedule the mouth movement action mouthActionTime = currentTime + 100; fishState = 1; // jump to a talking state } } else if (currentTime > mouthActionTime + 100) { //if we're beyond the scheduled talking time, halt the motors bodyMotor.halt(); mouthMotor.halt(); } if (currentTime - lastActionTime > 1500) { //if Billy hasn't done anything in a while, we need to show he's bored lastActionTime = currentTime + floor(random(30, 60)) * 1000L; //you can adjust the numbers here to change how often he flaps fishState = 2; //jump to a flapping state! } break; case 1: //TALKING if (currentTime < mouthActionTime) { //if we have a scheduled mouthActionTime in the future.... if (talking) { // and if we think we should be talking openMouth(); // then open the mouth and articulate the body lastActionTime = currentTime; articulateBody(true); } } else { // otherwise, close the mouth, don't articulate the body, and set talking to false closeMouth(); articulateBody(false); talking = false; fishState = 0; //jump back to waiting state } break; case 2: //GOTTA FLAP! //Serial.println("I'm bored. Gotta flap."); flap(); fishState = 0; break; } } int updateSoundInput() { soundVolume = analogRead(soundPin); } void openMouth() { mouthMotor.halt(); //stop the mouth motor mouthMotor.setSpeed(220); //set the mouth motor speed mouthMotor.forward(); //open the mouth } void closeMouth() { mouthMotor.halt(); //stop the mouth motor mouthMotor.setSpeed(180); //set the mouth motor speed mouthMotor.backward(); // close the mouth } void articulateBody(bool talking) { //function for articulating the body if (talking) { //if Billy is talking if (currentTime > bodyActionTime) { // and if we don't have a scheduled body movement int r = floor(random(0, 8)); // create a random number between 0 and 7) if (r bodyActionTime) { //if we're beyond the scheduled body action time bodyMotor.halt(); //stop the body motor bodyActionTime = currentTime + floor(random(20, 50)); //set the next scheduled body action to current time plus .02 to .05 seconds } } } void flap() { bodyMotor.setSpeed(180); //set the body motor to full speed bodyMotor.backward(); //move the body motor to raise the tail delay(500); //wait a bit, for dramatic effect bodyMotor.halt(); //halt the motor } 头文件 #ifndef MX1508_h #define MX1508_h #include "Arduino.h" typedef enum { FAST_DECAY = 0, // set non-PWM pin low SLOW_DECAY = 1 // set non-PWM pin high } DecayMode; typedef enum { PWM_1PIN = 1, PWM_2PIN = 2 } NumOfPwmPins; class MX1508 { public: MX1508(uint8_t pinIN1, uint8_t pinIN2); // default fast decay, 2 pwm pins MX1508(uint8_t pinIN1, uint8_t pinIN2, DecayMode decayMode, NumOfPwmPins numPWM); void motorGo(long pwmVal); // void setResolution(unsigned int resolution); int getPWM(); void stopMotor(); void analogWrite16(uint8_t pin, uint16_t val); void setPWM16(uint8_t prescaler, unsigned int resolution); private: uint8_t _pinIN1; uint8_t _pinIN2; bool _useAnalogWrite16 = false; int _pwmVal; int _pwmResolution = 255; //max resolution of pwm, default is 255. DecayMode _whichMode; NumOfPwmPins _numPwmPins; }; #endif 源文件 #include "MX1508.h" MX1508::MX1508( uint8_t pinIN1, uint8_t pinIN2) { _pinIN1 = pinIN1; // always a PWM pin _pinIN2 = pinIN2; // can be a non-Pwm pin. _whichMode = FAST_DECAY; _numPwmPins = PWM_2PIN; pinMode(_pinIN1, OUTPUT); pinMode(_pinIN2, OUTPUT); } MX1508::MX1508( uint8_t pinIN1, uint8_t pinIN2, DecayMode decayMode, NumOfPwmPins numPins) { _pinIN1 = pinIN1; // always a PWM pin _pinIN2 = pinIN2; // can be a non-Pwm pin. _whichMode = decayMode; _numPwmPins = numPins; pinMode(_pinIN1, OUTPUT); pinMode(_pinIN2, OUTPUT); } int MX1508::getPWM() { return _pwmVal; } void MX1508::stopMotor() { digitalWrite(_pinIN1, LOW); digitalWrite(_pinIN2, LOW); } void MX1508::setResolution(unsigned int pwmResolution) { _pwmResolution = pwmResolution; if(_useAnalogWrite16) ICR1 = pwmResolution; } void MX1508::setPWM16(uint8_t prescaler, unsigned int resolution){ if(prescaler > 5 || prescaler == 0) prescaler = 3; // default to 64 if not in range. DDRB |= _BV(PB1) | _BV(PB2); /* set pin 9and 10 as outputs */ TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11); // non-inverting PWM, mode 14 fastPWM, TOP =ICR1 TCCR1B = _BV(WGM13) | _BV(WGM12) | prescaler ; // rescaler must be 1->5, 1,8,64,256,1028 respectively ICR1 = resolution; _pwmResolution = resolution; _useAnalogWrite16 = true; } void MX1508::analogWrite16(uint8_t pin, uint16_t val) { if(_useAnalogWrite16){ if(val < 5) val =5; switch (pin) { case 9: OCR1A = val; break; case 10: OCR1B = val; break; default: analogWrite(pin,val); } }else{ analogWrite(pin, val); } } void MX1508::motorGo(long pwmSpeed) { _pwmVal = pwmSpeed; // if set decay mode is set as fast decay mode if (this->_whichMode == FAST_DECAY) { if (pwmSpeed >= 0) { //forward fast decay if(_numPwmPins == PWM_1PIN)digitalWrite(_pinIN2, LOW); else analogWrite16(_pinIN2, 1); analogWrite16(_pinIN1, pwmSpeed); } else if (this->_numPwmPins == PWM_2PIN) { // reverse fast decay pwmSpeed *= -1; analogWrite16(_pinIN1, 1); analogWrite16(_pinIN2, pwmSpeed); } else if (this->_numPwmPins == PWM_1PIN) { // reverse slow decay pwmSpeed *= -1; pwmSpeed = map(pwmSpeed, 0, _pwmResolution, _pwmResolution, 0); digitalWrite(_pinIN2, HIGH); analogWrite16(_pinIN1, pwmSpeed); } } // if decay mode is set as slow decay mode else { if (pwmSpeed >= 0) { // forward slow decay pwmSpeed = map(pwmSpeed, 0, _pwmResolution, _pwmResolution, 0); if(_numPwmPins == PWM_1PIN)digitalWrite(_pinIN1, HIGH); else analogWrite16(_pinIN1, _pwmResolution); analogWrite16(_pinIN2, pwmSpeed); } else if (this->_numPwmPins == PWM_2PIN) { // reverse slow decay pwmSpeed *= -1; pwmSpeed = map(pwmSpeed, 0, _pwmResolution, _pwmResolution, 0); analogWrite16(_pinIN2, _pwmResolution); analogWrite16(_pinIN1, pwmSpeed); } else if (this->_numPwmPins == PWM_1PIN) { // reverse fast decay pwmSpeed *= -1; digitalWrite(_pinIN1, LOW); analogWrite16(_pinIN2, pwmSpeed); } } }