3164| 5
|
[已解决] 串口不显示,小车不动 |
#include <DFMobile.h> #include <Metro.h> #include "GoBLE.h" int joystickX, joystickY; int buttonState[7]; 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[SWITCH_UP] = Goble.readSwitchUp(); buttonState[SWITCH_DOWN] = Goble.readSwitchDown(); buttonState[SWITCH_LEFT] = Goble.readSwitchLeft(); buttonState[SWITCH_RIGHT] = Goble.readSwitchRight(); buttonState[SWITCH_SELECT] = Goble.readSwitchSelect(); buttonState[SWITCH_START] = 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[SWITCH_UP]) { digitalWrite(directionPin_M2,LOW); digitalWrite(directionPin_M1,HIGH);} if (buttonState[SWITCH_DOWN]) { digitalWrite(directionPin_M2,HIGH); digitalWrite(directionPin_M1,LOW);} if (buttonState[SWITCH_LEFT]) { digitalWrite(directionPin_M2,HIGH); digitalWrite(directionPin_M1,HIGH);} if (buttonState[SWITCH_RIGHT]) { 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); } } } } } |
© 2013-2024 Comsenz Inc. Powered by Discuz! X3.4 Licensed