“乐高遥控小车”的版本间的差异
(→程序说明) |
(→程序说明) |
||
| 第194行: | 第194行: | ||
| − | |||
| − | |||
| − | |||
#include <mCookieLEGO.h> | #include <mCookieLEGO.h> | ||
#include <Microduino_Protocol_HardSer.h> | #include <Microduino_Protocol_HardSer.h> | ||
| 第225行: | 第222行: | ||
speedLeft = map(Data[1], 1000, 2000, -255, 255); | speedLeft = map(Data[1], 1000, 2000, -255, 255); | ||
speedRight = speedLeft; | speedRight = speedLeft; | ||
| − | int speedTurn = map(Data[ | + | int speedTurn = map(Data[2], 1000, 2000, -255, 255); |
if(speedTurn < 0){ | if(speedTurn < 0){ | ||
speedLeft += speedTurn; | speedLeft += speedTurn; | ||
| 第232行: | 第229行: | ||
speedRight -= speedTurn; | speedRight -= speedTurn; | ||
} | } | ||
| + | refreshSpeed(); | ||
break; | break; | ||
// default: | // default: | ||
| 第237行: | 第235行: | ||
} | } | ||
} | } | ||
| − | + | ||
delay(10); | delay(10); | ||
| − | } | + | } |
| − | void refreshSpeed{ | + | void refreshSpeed(){ |
m.motor_setFixedDrive(mCookieLEGO::M3, speedLeft); | m.motor_setFixedDrive(mCookieLEGO::M3, speedLeft); | ||
m.motor_setFixedDrive(mCookieLEGO::M4, speedRight); | m.motor_setFixedDrive(mCookieLEGO::M4, speedRight); | ||
| + | Serial.print("Left: "); | ||
| + | Serial.print(speedLeft); | ||
| + | Serial.print(" Right: "); | ||
| + | Serial.println(speedRight); | ||
} | } | ||
| − | |||
| − | |||
| − | |||
2016年4月26日 (二) 01:40的版本
| Language | English |
|---|
|
概述
材料清单
实验原理
程序下载
程序烧写
拼装过程
操作说明蓝牙遥控指南
疑难解答/FAQ
|
- include <mCookieLEGO.h>
- include <Microduino_Protocol_HardSer.h>
- include "Wire.h"
uint16_t Data[8];
int speedLeft = 0;
int speedRight = 0;
Protocol ProtocolB(&Serial1, TYPE_NUM);
mCookieLEGO m;
void setup(){
Wire.begin(); Serial.begin(9600); ProtocolB.begin(9600); //9600/19200/38400 m.configSensorType(mCookieLEGO::S1, mCookieLEGO::SENSOR_ULTRA); m.configConnection(0xFFFF);
} uint8_t dis;
void loop(){
int sta = ProtocolB.parse(Data, MODE_WHILE);
if (sta != P_NONE) {
switch (sta) {
case P_FINE:
speedLeft = map(Data[1], 1000, 2000, -255, 255);
speedRight = speedLeft;
int speedTurn = map(Data[2], 1000, 2000, -255, 255);
if(speedTurn < 0){
speedLeft += speedTurn;
}
else{
speedRight -= speedTurn;
}
refreshSpeed();
break;
// default: // break;
} } delay(10); }
void refreshSpeed(){
m.motor_setFixedDrive(mCookieLEGO::M3, speedLeft);
m.motor_setFixedDrive(mCookieLEGO::M4, speedRight);
Serial.print("Left: ");
Serial.print(speedLeft);
Serial.print(" Right: ");
Serial.println(speedRight);
}