新手问题(又出现了一个编程错误的问题)-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5405|回复: 2

[过期] 新手问题(又出现了一个编程错误的问题)

[复制链接]
发表于 2013-3-24 23:14 | 显示全部楼层 |阅读模式
本帖最后由 hetzenauer 于 2013-3-26 15:47 编辑

今天收到apc220无线传输模块,但是设置好了以后使用下载的RF-ANET软件却一直跳出错误提示,说没有发现串行端口,更新了驱动程序以后还是老样子,去硬件管理器里面看了串口是正常的,不知道怎么才能解决。
另外一个问题是今天做履带底盘前进后退程序的时候,我根据《arduino开发实战指南》里面的程序烧入之后,发现只有用USB线连接电脑的时候芯片才正常工作,如果不连接电脑只连接电源的话就只是间断前进,不知何故,希望各位高人不吝赐教。多谢 1.jpg
2.jpg

编写MotorCar库的时候又出现问题,我在头文件MotorCar.h里面已经定义了私有函数_speedLeftPin,_speedRightPin,_dirLeftPin,_dirRightPin以及公有函数MotorCar(int,int,int,int),forward,back,turnLeft,turnRight,turnLeftOrigin,turnRightOrigin,stop,但是在试运行的时候,编译时提示cpp里面每个子函数都有问题

#include <MotorCar.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);
}
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(_speedLeftPin,_speed);
  analogWrite(_speedRightPin,0);
}
void MotorCar::turnRightOrigin(int _speed)
{
  digitalWrite(_dirRightPin,LOW);
  digitalWrite(_dirLeftPin,HIGH);
  analogWrite(_speedRightPin,_speed);
  analogWrite(_speedLeftPin,_speed);
}
void MotorCar::turnLeftOrigin(int _speed)
{
  digitalWrite(_dirRightPin,HIGH);
  digitalWrite(_dirLeftPin,LOW);
  analogWrite(_speedRightPin,_speed);
  analogWrite(_speedLeftPin,_speed);
}
void MotorCar::stop()
{
  analogWrite(_speedRightPin,0);
  analogWrite(_speedLeftPin,0);
}

提示是
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp: In constructor 'MotorCar::MotorCar(int, int, int, int)':
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:12: error: 'OUTPUT' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:12: error: 'pinMode' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp: In member function 'void MotorCar::forward(int)':
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:19: error: 'HIGH' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:19: error: 'digitalWrite' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:21: error: 'analogWrite' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp: In member function 'void MotorCar::back(int)':
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:26: error: 'LOW' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:26: error: 'digitalWrite' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:28: error: 'analogWrite' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp: In member function 'void MotorCar::turnLeft(int)':
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:33: error: 'HIGH' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:33: error: 'digitalWrite' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:34: error: 'analogWrite' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp: In member function 'void MotorCar::turnRight(int)':
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:39: error: 'HIGH' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:39: error: 'digitalWrite' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:40: error: 'analogWrite' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp: In member function 'void MotorCar::turnRightOrigin(int)':
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:45: error: 'LOW' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:45: error: 'digitalWrite' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:46: error: 'HIGH' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:47: error: 'analogWrite' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp: In member function 'void MotorCar::turnLeftOrigin(int)':
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:52: error: 'HIGH' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:52: error: 'digitalWrite' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:53: error: 'LOW' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:54: error: 'analogWrite' was not declared in this scope
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp: In member function 'void MotorCar::stop()':
E:\arduino-1.0.3-windows\arduino-1.0.3\libraries\MotorCar\MotorCar.cpp:59: error: 'analogWrite' was not declared in this scope

HIGH,LOW,pinMode之类的我怎么定义啊,这不应该是原本就自带的么
发表于 2013-3-25 11:51 | 显示全部楼层
第一个问题我没有遇到,不太清楚。第二个问题我刚好跟你相反,USB连线时,小车间断前进,必须使用外部电源。原因在于USB提供的电流不够大,导致系统不断的复位。所以可能是你的外部电源提供的电流有些小导致的吧,你可以尝试换个外部电源,能够提供大的电流
 楼主| 发表于 2013-3-25 18:26 | 显示全部楼层
残梦-DRobot 发表于 2013-3-25 11:51
第一个问题我没有遇到,不太清楚。第二个问题我刚好跟你相反,USB连线时,小车间断前进,必须使用外部电源 ...

我只连接电脑的时候和你一个情况,我估计就是电流不够,所以加了外接电源,结果两个同时插上的时候一切正常,拔了USB线以后就只能做一个动作了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-12-3 05:45 , Processed in 0.113661 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表