暮雪朝阳 发表于 2019-7-23 21:59:06

串口不显示,小车不动

#include <DFMobile.h>

#include <Metro.h>
#include "GoBLE.h"
int joystickX, joystickY;
int buttonState;
Metro motorMetro = Metro(50);
int LeftWheelSpeed;
int RightWheelSpeed;
DFMobile Robot (4, 5, 7, 6);
void setup(){
Goble.begin();
Serial.begin(115200);
}

void loop() {
if(Goble.available()){
    joystickX = Goble.readJoystickX();
    joystickY = Goble.readJoystickY();
   
    buttonState   = Goble.readSwitchUp();
    buttonState   = Goble.readSwitchDown();
    buttonState   = Goble.readSwitchLeft();
    buttonState= Goble.readSwitchRight();
    buttonState = Goble.readSwitchSelect();
    buttonState= Goble.readSwitchStart();
   
    Serial.print("Joystick Value: ");
    Serial.print(joystickX);
    Serial.print("");
    Serial.println(joystickY);
   
    for (int i = 1; i < 7; i++) {
      Serial.print("Button ID: ");
      Serial.print(i);
      Serial.print("\t State: ");
      if (buttonState == PRESSED)   Serial.println("Pressed!");
      if (buttonState == RELEASED)Serial.println("Released!");
      int speedPin_M1 = 5;   
int speedPin_M2 = 6;
int directionPin_M1 = 4;
int directionPin_M2 = 7;
      if (buttonState) {
digitalWrite(directionPin_M2,LOW);   
digitalWrite(directionPin_M1,HIGH);}
   if (buttonState) {
digitalWrite(directionPin_M2,HIGH);   
digitalWrite(directionPin_M1,LOW);}
   if (buttonState) {
digitalWrite(directionPin_M2,HIGH);   
digitalWrite(directionPin_M1,HIGH);}
   if (buttonState) {
digitalWrite(directionPin_M2,LOW);   
digitalWrite(directionPin_M1,LOW);}

   if (motorMetro.check()) {
      if (joystickX > 200 ||joystickX < -200) {    //when joystick X is pushed up
          LeftWheelSpeed = joystickX;                //Both wheels move forward
          RightWheelSpeed = joystickX;
          Robot.Speed (LeftWheelSpeed, RightWheelSpeed);
          Serial.print("move ");

      }

      else if (joystickY > 200 ||joystickY < -200) {      /file:///C:\Users\薛磊\AppData\Roaming\Tencent\QQTempSys\@IR3P(8S$C$Z$TY~5I{QEPC.gif right
          LeftWheelSpeed = joystickY - 80;
          RightWheelSpeed = -joystickY- 80;
          Robot.Speed(LeftWheelSpeed, RightWheelSpeed);
          Serial.print("twist ");

      }

      else if (joystickX == 0 && joystickY== 0) {
          Robot.Speed(0, 0);
      }
    }
   
}
}
}

shzrzxlee 发表于 2019-7-23 22:32:43

串口不显示 不能上传的

shzrzxlee 发表于 2019-7-23 22:35:28

串口不显示 要么USB接口接触不好,第一次用的话是驱动没装

KIKIYA 发表于 2019-7-24 11:05:37

什么小车?

shzrzxlee 发表于 2019-7-24 15:35:57

DFMobile Robot (4, 5, 7, 6);

gada888 发表于 2019-8-6 09:29:34

数据线没连好,或者代码写的有问题。
页: [1]
查看完整版本: 串口不显示,小车不动