- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
希望这不会太具体以保证问题结束。
我在校园里与一个研究小组合作,学习机器人技术和自动化。我目前的任务是学习 Arduino 电机扩展板的内部和外部,并将其与蓝牙扩展板结合起来。
我们正在使用 this bluetooth shield和 this motor shield .如有必要,我们还可以访问 this motor shield .
在大多数情况下,我当前的代码分别适用于每个板,但是当我将它们组合在一起时,突然就没有任何效果了。电机部分仅在蓝牙特定代码被注释掉时才工作。这使我得出结论,存在管脚冲突。话虽这么说,有什么办法可以让它发挥作用吗?任何解决方法等。
这是我正在使用的代码,以防我的代码出现问题。
#include <SoftwareSerial.h> // Necessary to use the bluetooth Software Serial Port
#define RxD 7
#define TxD 6
#define DEBUG_ENABLED 1
SoftwareSerial bts(RxD,TxD);
int drive = 12; // Pin definitions
int brake = 9;
int power = 3;
const int DRIVE_F = 1; // Command options returned from parseCommand
const int DRIVE_B = 2;
const int LEFT = 3;
const int RIGHT = 4;
const int STOP = 5;
const int NONE = 0;
void setup()
{
pinMode(RxD, INPUT); // Set up pin modes
pinMode(TxD, OUTPUT);
pinMode(drive, OUTPUT);
pinMode(brake, OUTPUT);
analogWrite(power, 80);
digitalWrite(drive, LOW);
digitalWrite(brake, HIGH);
setupBlueToothConnection();
}
void loop()
{
switch(parseCommand())
{
case DRIVE_F: // Switch through command returns.
forward();
bts.println("Driving forward");
delay(1000);
fullStop(); // Go ahead and stop. Don't want
break; // the car to run infinitely yet.
case DRIVE_B:
backward();
bts.println("Driving backward");
delay(1000);
fullStop();
break;
case LEFT:
turnLeft(); // These do nothing for now. Just here for later.
break;
case RIGHT:
turnRight();
break;
case STOP:
fullStop();
bts.println("Stopping"); // Stop the car. Will be needed later.
break;
default:
turnLeft(); // If invalid command returned,
delay(250); // wiggle wheels for an error message.
turnRight();
delay(250);
turnStraight();
break;
}
}
void setupBlueToothConnection() // Not exactly sure why all this is needed. It was in the sample code, so I kept it all
{
bts.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
bts.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
bts.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
bts.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
bts.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
bts.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
bts.flush();
}
void forward()
{
digitalWrite(drive, HIGH);
digitalWrite(brake, LOW);
}
void backward()
{
digitalWrite(drive, LOW);
digitalWrite(brake, LOW);
}
void fullStop()
{
digitalWrite(brake, HIGH);
}
void turnRight()
{
}
void turnLeft()
{
}
void turnStraight()
{
}
int parseCommand()
{
String command = ""; // String to hold the command
char recvChar; // Char to hold each character.
while(true)
{
if(bts.available())
{
recvChar = bts.read();
if(recvChar == 13)
bts.println(); // If char received is an ASCII 13, carriage-return/enter key
else // print new line.
bts.print(recvChar); // Else, print received char to serial so user can see his/her input.
if(recvChar != -1 && recvChar != 13)
command += recvChar; // If not -1 (no input received from read()) or 13, concat it with command
if(recvChar == 13)
{ // If enter pressed, check the command variable.
if( command == "forward" )
return DRIVE_F;
else if( command == "back" || command == "backward")
return DRIVE_B;
else if( command == "stop" )
return STOP;
else
{
bts.println("'" + command + "' is an invalid command.");
return NONE; // If invalid, return NONE and print error.
}
}
}
}
}
提前致谢。
最佳答案
看看这两个屏蔽,我怀疑引脚 6 有引脚冲突。Arduino 电机屏蔽暴露了“2 个用于两个 Aanlog 输出的 TinkerKit 连接器(中间为橙色),连接到引脚 D5 和 D6 上的 PWM 输出。”它们可能在 D6 上有一个下拉或上拉电阻,这会干扰您的蓝牙 UART 通信。
有没有办法通过引脚 0 和 1 路由您的蓝牙通信?如果这样做,您必须使用蓝牙而不是 USB。
也许更简单的方法是切换到电机护罩,只是一个电机护罩并且需要更少的引脚。类似 Ardumotor from Sparkfun 的东西只使用引脚 3, 11, 12, and 13 .
现在有一个 dedicated group for robotics .
关于c - 结合使用 Arduino Motor Shield 和 Bluetooth Shield,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15061334/
我在网上搜索但没有找到任何合适的文章解释如何使用 javascript 使用 WCF 服务,尤其是 WebScriptEndpoint。 任何人都可以对此给出任何指导吗? 谢谢 最佳答案 这是一篇关于
我正在编写一个将运行 Linux 命令的 C 程序,例如: cat/etc/passwd | grep 列表 |剪切-c 1-5 我没有任何结果 *这里 parent 等待第一个 child (chi
所以我正在尝试处理文件上传,然后将该文件作为二进制文件存储到数据库中。在我存储它之后,我尝试在给定的 URL 上提供文件。我似乎找不到适合这里的方法。我需要使用数据库,因为我使用 Google 应用引
我正在尝试制作一个宏,将下面的公式添加到单元格中,然后将其拖到整个列中并在 H 列中复制相同的公式 我想在 F 和 H 列中输入公式的数据 Range("F1").formula = "=IF(ISE
问题类似于this one ,但我想使用 OperatorPrecedenceParser 解析带有函数应用程序的表达式在 FParsec . 这是我的 AST: type Expression =
我想通过使用 sequelize 和 node.js 将这个查询更改为代码取决于在哪里 select COUNT(gender) as genderCount from customers where
我正在使用GNU bash,版本5.0.3(1)-发行版(x86_64-pc-linux-gnu),我想知道为什么简单的赋值语句会出现语法错误: #/bin/bash var1=/tmp
这里,为什么我的代码在 IE 中不起作用。我的代码适用于所有浏览器。没有问题。但是当我在 IE 上运行我的项目时,它发现错误。 而且我的 jquery 类和 insertadjacentHTMl 也不
我正在尝试更改标签的innerHTML。我无权访问该表单,因此无法编辑 HTML。标签具有的唯一标识符是“for”属性。 这是输入和标签的结构:
我有一个页面,我可以在其中返回用户帖子,可以使用一些 jquery 代码对这些帖子进行即时评论,在发布新评论后,我在帖子下插入新评论以及删除 按钮。问题是 Delete 按钮在新插入的元素上不起作用,
我有一个大约有 20 列的“管道分隔”文件。我只想使用 sha1sum 散列第一列,它是一个数字,如帐号,并按原样返回其余列。 使用 awk 或 sed 执行此操作的最佳方法是什么? Accounti
我需要将以下内容插入到我的表中...我的用户表有五列 id、用户名、密码、名称、条目。 (我还没有提交任何东西到条目中,我稍后会使用 php 来做)但由于某种原因我不断收到这个错误:#1054 - U
所以我试图有一个输入字段,我可以在其中输入任何字符,但然后将输入的值小写,删除任何非字母数字字符,留下“。”而不是空格。 例如,如果我输入: 地球的 70% 是水,-!*#$^^ & 30% 土地 输
我正在尝试做一些我认为非常简单的事情,但出于某种原因我没有得到想要的结果?我是 javascript 的新手,但对 java 有经验,所以我相信我没有使用某种正确的规则。 这是一个获取输入值、检查选择
我想使用 angularjs 从 mysql 数据库加载数据。 这就是应用程序的工作原理;用户登录,他们的用户名存储在 cookie 中。该用户名显示在主页上 我想获取这个值并通过 angularjs
我正在使用 autoLayout,我想在 UITableViewCell 上放置一个 UIlabel,它应该始终位于单元格的右侧和右侧的中心。 这就是我想要实现的目标 所以在这里你可以看到我正在谈论的
我需要与 MySql 等效的 elasticsearch 查询。我的 sql 查询: SELECT DISTINCT t.product_id AS id FROM tbl_sup_price t
我正在实现代码以使用 JSON。 func setup() { if let flickrURL = NSURL(string: "https://api.flickr.com/
我尝试使用for循环声明变量,然后测试cols和rols是否相同。如果是,它将运行递归函数。但是,我在 javascript 中执行 do 时遇到问题。有人可以帮忙吗? 现在,在比较 col.1 和
我举了一个我正在处理的问题的简短示例。 HTML代码: 1 2 3 CSS 代码: .BB a:hover{ color: #000; } .BB > li:after {
我是一名优秀的程序员,十分优秀!