我见过使用accelometer传感器的代码,Android的UI上没有左右按钮,但RC汽车仍然可以通过将Android倾斜到所需方向来左转或右转。是否可以使用按钮来实现?
我在线搜索并找到了这个例子;
public void leftClick(View v) {
mInstructionList.add(new Instruction(InstructionCommand.LEFT));
mListAdapter.notifyDataSetChanged();
}
public void rightClick(View v) {
mInstructionList.add(new Instruction(InstructionCommand.RIGHT));
mListAdapter.notifyDataSetChanged();
}
public void forwardClick(View v) {
mInstructionList.add(new Instruction(InstructionCommand.FORWARD));
mListAdapter.notifyDataSetChanged();
}
public void reverseClick(View v) {
mInstructionList.add(new Instruction(InstructionCommand.REVERSE));
mListAdapter.notifyDataSetChanged();
}
public void stopClick(View v) {
mInstructionList.add(new Instruction(InstructionCommand.STOP));
mListAdapter.notifyDataSetChanged();
}
这是对的吗?那么Arduino如何识别Android上的按钮点击?