你的附件我查看过了,属于c++基本语法错误。
错误全部在MotorCar.cpp文件里面
下面是我更正后的代码:
[mw_shl_code=cpp,true]/************************************************************
MotoCar��캯��
�����ܣ��������ڿ���ֱ���������
��ڲ��� _slpin,��ʾ���������ٶȵ����
_dlpin,��ʾ�������ַ�������
_srpin,��ʾ���������ٶȵ����
_drpin,��ʾ�������ַ�������
************************************************************/
#include "MotorCar.h"
#include "Arduino.h"
MotorCar::MotorCar (int _slpin, int _dlpin, int _srpin, int _drpin)
{
_speedLeftPin = _slpin;
_speedRightPin = _srpin;
_dirLeftPin = _dlpin;
_dirRightPin = _drpin;
pinMode(_speedLeftPin, OUTPUT);
pinMode(_speedRightPin, OUTPUT);
pinMode(_dirLeftPin, OUTPUT);
pinMode(_dirRightPin, OUTPUT);
}
/**********************************************************
ǰ���Ӻ���
_speed ǰ���ٶ� 0����255
***********************************************************/
void MotorCar::forward(int _speed)
{
digitalWrite(_dirRightPin, HIGH);
digitalWrite(_dirLeftPin, HIGH);
analogWrite(_speedRightPin, _speed);
analogWrite(_speedLeftPin, _speed);
}
/***********************************************************
�����Ӻ���
***********************************************************/
void MotorCar::back(int _speed)
{
digitalWrite(_dirRightPin, LOW);
digitalWrite(_dirLeftPin, LOW);
analogWrite(_speedRightPin, _speed);
analogWrite(_speedLeftPin, _speed);
}
/************************************************************
��ת�Ӻ���
**********************************************************/
void MotorCar::turnLeft(int _speed)
{
digitalWrite(_dirRightPin,HIGH);
analogWrite(_speedRightPin, _speed);
analogWrite(_speedLeftPin, 0);
}
/***********************************************************
��ת�Ӻ���
***********************************************************/
void MotorCar::turnRight (int _speed)
{
digitalWrite(_dirLeftPin, HIGH);
analogWrite(_speedRightPin, 0);
analogWrite(_speedLeftPin, _speed);
}
/***********************************************************
ԭ����ת�Ӻ���
**********************************************************/
void MotorCar::turnLeftOrigin(int _speed)
{
digitalWrite(_dirRightPin,HIGH);
digitalWrite(_dirLeftPin, LOW);
analogWrite(_speedRightPin, _speed);
analogWrite(_speedLeftPin,_speed);
}
/***********************************************************
ԭ����ת�Ӻ���
***********************************************************/
void MotorCar::turnRightOrigin(int _speed)
{
digitalWrite(_dirLeftPin, HIGH);
digitalWrite(_dirRightPin, LOW);
analogWrite(_speedRightPin, _speed);
analogWrite(_speedLeftPin, _speed);
}
/************************************************************
ֹͣ�Ӻ���
************************************************************/
void MotorCar::stop()
{
analogWrite(_speedRightPin, 0);
analogWrite(_speedLeftPin, 0);
}[/mw_shl_code]
错误:
1、需要 include 头文件,这样才能调用相应的函数。
2、MotorCar::MotorCar (int _slpin, int _dlpin, int _srpin, int _drpin) 此处,少了一个 冒号
3、基本的变量明写错,还不止错了一个地方。 此类问题一定要谨慎。 |